/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_voip_fuc.c

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	wayne.lee	2013/9/26	Create
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <errno.h>

#include "omci_adpt_common.h"
#include "omci_adpt_general.h"
#include "omci_adpt_voip.h"
#include "omci_adpt_private_voip.h"

/*******************************************************************************************************************************
globle variable

********************************************************************************************************************************/

static int setSipAgentServersForSipUserData(uint16_t agentInstid, uint16_t entryId);
static int setVoIPSvcProfileForSipUserData(uint16_t instId, uint16_t entryId);

#define LARGE_STRING_ME_MAX_LEN (25*15)
#define SIP_USER_DATA_USER_PART_AOR_LEN   2

/*******************************************************************************************************************************
9.9.1 Physical path termination point POTS UNI

********************************************************************************************************************************/
static attribute_func_t pptpPotsUNIAdminStatusFunc = {
	getPptpPotsUNIAdminStatus,
	setPptpPotsUNIAdminStatus
};

static attribute_func_t pptpPotsUNIARCFunc = {
	NULL,
	setPptpPotsUNIARCValue
};

static attribute_func_t pptpPotsUNIARCIntervalFunc = {
	NULL,
	NULL //setPptpPotsUNIARCIntervalValue, no need implement in omci2.0
};
static attribute_func_t PptpPotsUNIRxGainFunc = {
	getPptpPotsUNIRxGain,
	setPptpPotsUNIRxGain
};

static attribute_func_t PptpPotsUNITxGainFunc = {
	getPptpPotsUNITxGain,
	setPptpPotsUNITxGain
};

static attribute_func_t PptpPotsUNIHookStateFunc = {
	getPptpPotsUNIHookState,
	NULL
};

omci_attr_dscp_t omci_attr_pptp_pots_uni_op[]={
	{0, "meId",						2,	ATTR_ACCESS_R,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,		&generalAttrFunc},
	{1, "Administrative state",		1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,		&pptpPotsUNIAdminStatusFunc},
	{2, "Interworking TP pointer",	2,	ATTR_ACCESS_R_W,	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,		&generalAttrFunc},
	{3, "ARC",						1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,		&pptpPotsUNIARCFunc},
	{4, "ARC interval",				1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, 	&pptpPotsUNIARCIntervalFunc},
	{5, "Impedance",				1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{6, "Transmission path",		1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_ENUM,		    ATTR_FULLY_SUPPORT,		&generalAttrFunc},
	{7, "Rx gain",					1, 	ATTR_ACCESS_R_W,	ATTR_FORMAT_SIGNED_INT,		ATTR_FULLY_SUPPORT,  	&PptpPotsUNIRxGainFunc},
	{8, "Tx gain",					1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_SIGNED_INT, 	ATTR_FULLY_SUPPORT, 	&PptpPotsUNITxGainFunc},
	{9, "Operational state",		1,	ATTR_ACCESS_R,		ATTR_FORMAT_UNSIGNED_INT, 	ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{10, "Hook state",				1,	ATTR_ACCESS_R,		ATTR_FORMAT_ENUM, 	        ATTR_FULLY_SUPPORT, 	&PptpPotsUNIHookStateFunc},
	{11, "POTS holdover time",		2,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT, 	ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{12, "Nominal feed voltage",	1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_ENUM,			ATTR_FULLY_SUPPORT,     &generalAttrFunc},
	{13, "Loss of sotfswitch",		1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,     &generalAttrFunc}, 
	{255, "",						0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_pptp_pots_uni_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
	omci_me_pptp_pots_uni_test_op,
};

omci_pptp_pots_uni_t omci_pptp_pots_uni_attr_data = {0};

omci_attr_t omci_pptp_pots_uni_attr ={
	(uint8_t *)&omci_pptp_pots_uni_attr_data,
	sizeof(omci_pptp_pots_uni_attr_data),
};

/*******************************************************************************************************************************
9.9.2 sip user data

********************************************************************************************************************************/
static attribute_func_t sipUserDatauserpartaorFunc = {
	NULL,
	setSipUserDataUserPartAOR
};

static attribute_func_t sipUserDataDispNameFunc = {
	getSipUserDataDispName,
	setSipUserDataDispName
};

static attribute_func_t sipUserDataUserPassFunc = {
	NULL,
	setSipUserDataUserPass
};
static attribute_func_t sipUserDataSipURIFunc = {
	NULL,
	setSipUserDataSipURI
};

static attribute_func_t sipUserDataExpTimeFunc = {
	getSipUserDataExpTime,
	setSipUserDataExpTime
};

static attribute_func_t sipUserDataPPTPPointerFunc = {
	NULL,
	setSipUserDataPPTPPointer
};

omci_attr_dscp_t omci_attr_sip_user_data_op[]={
	{0, "meId",							2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "SIP agent pointer",			2,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "User part AOR",				2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&sipUserDatauserpartaorFunc},
	{3, "SIP display name",				25,	ATTR_ACCESS_R_W, 				ATTR_FORMAT_STRING,			ATTR_FULLY_SUPPORT, &sipUserDataDispNameFunc},
	{4, "Username,password",			2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&sipUserDataUserPassFunc},
	{5, "voicemail server SIP URI",		2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&sipUserDataSipURIFunc},
	{6, "voicemail subscri exp time",	4,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&sipUserDataExpTimeFunc},
	{7, "network dial plan pointer", 	2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{8, "App serv profile pointer", 	2,  ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{9, "feature code pointer", 		2,  ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{10, "PPTP pointer", 				2,  ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&sipUserDataPPTPPointerFunc},
	{11, "Release timer", 				1,  ATTR_ACCESS_R_W, 				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{12, "ROH timer", 					1,  ATTR_ACCESS_R_W, 				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};


omci_me_func_t omci_me_sip_user_data_op ={
	omci_me_sip_user_data_create_op,
	omci_me_sip_user_data_del_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_sip_user_data_t omci_sip_user_data_attr_data = {0};

omci_attr_t omci_sip_user_data_attr ={
	(uint8_t *)&omci_sip_user_data_attr_data,
	sizeof(omci_sip_user_data_attr_data),
};

/*******************************************************************************************************************************
9.9.3 sip config data

********************************************************************************************************************************/
static attribute_func_t sipAgentCfgDataProxyAddrFunc = {
	NULL,
	setSipAgentCfgDataProxyAddr
};

static attribute_func_t sipAgentCfgDataOutBoundProxyAddrFunc = {
	NULL,
	setSipAgentCfgDataOutBoundProxyAddr
};

static attribute_func_t sipAgentCfgDataSipRegExpTimeFunc = {
	getSipAgentCfgDataSipRegExpTime,
	setSipAgentCfgDataSipRegExpTime
};

static attribute_func_t sipAgentCfgDataSIPReregTimeFunc = {
	getSipAgentCfgDataSIPReregTime,
	setSipAgentCfgDataSIPReregTime
};

static attribute_func_t sipAgentCfgDataSIPStatusFunc = {
	getSipAgentCfgDataSIPStatus,
	NULL
};

static attribute_func_t sipAgentCfgDataSIPRegistrarFunc = {
	NULL,
	NULL    //setSipAgentCfgDataSIPRegistrar
};

static attribute_func_t sipAgentCfgDataTcpUdpFunc = {
	NULL,
	setSipAgentCfgDataTcpUdp,
};

static attribute_func_t sipAgentCfgDataHostPartUriFunc = {
	NULL,
	setSipAgentCfgDataHostPartUri,
};

omci_attr_dscp_t    omci_attr_sip_agent_cfg_op[]={
	{0, "meID",                             2, ATTR_ACCESS_R_SET_CREATE,    ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{1, "Proxy server address pointer",     2, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_POINTER,         ATTR_FULLY_SUPPORT,  &sipAgentCfgDataProxyAddrFunc },
	{2, "Outbound proxy address pointer",   2, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_POINTER,         ATTR_FULLY_SUPPORT,  &sipAgentCfgDataOutBoundProxyAddrFunc },
	{3, "Primary SIP DNS",                  4, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{4, "Secondary SIP DNS",                4, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{5, "TCP/UDP pointer",                  2, ATTR_ACCESS_R_W,             ATTR_FORMAT_POINTER,         ATTR_FULLY_SUPPORT,  &sipAgentCfgDataTcpUdpFunc },
	{6, "SIP reg exp time",                 4, ATTR_ACCESS_R_W,             ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,  &sipAgentCfgDataSipRegExpTimeFunc },
	{7, "SIP rereg head start time",        4, ATTR_ACCESS_R_W,             ATTR_FORMAT_UNSIGNED_INT,    ATTR_FULLY_SUPPORT,  &sipAgentCfgDataSIPReregTimeFunc },
	{8, "Host part URI",                    2, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_POINTER,         ATTR_FULLY_SUPPORT,  &sipAgentCfgDataHostPartUriFunc },
	{9, "SIP status",                       1, ATTR_ACCESS_R,               ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,  &sipAgentCfgDataSIPStatusFunc },
	{10, "SIP registrar",                   2, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_POINTER,         ATTR_FULLY_SUPPORT,  &sipAgentCfgDataSIPRegistrarFunc },
	{11, "Softswitch",                      4, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_STRING,          ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{12, "SIP response table",				5, ATTR_ACCESS_R_W,				ATTR_FORMAT_TABLE,		 	 ATTR_UNSUPPORT,  	  &generalAttrFunc },
	{13, "SIP option transmit control",     1, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{14, "SIP URI format",                  1, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_ENUM,            ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{15, "Redundant SIP agent pointer",     2, ATTR_ACCESS_R_W_SET_CREATE,  ATTR_FORMAT_POINTER,         ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{255, "", 							    0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_sip_agent_cfg_op ={
	omci_me_sip_agent_cfg_create_op,
	omci_me_sip_agent_cfg_del_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_sip_agent_cfg_t omci_sip_agent_cfg_attr_data = {0};

omci_attr_t omci_sip_agent_cfg_attr ={
	(uint8_t *)&omci_sip_agent_cfg_attr_data,
	sizeof(omci_sip_agent_cfg_attr_data),
};

/*******************************************************************************************************************************
9.9.4  VoIP voice CTP

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_voip_voice_ctp_op[]={
	{0, "meId", 						2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{1, "User protocol pointer", 		2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,	   ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{2, "PPTP pointer",		            2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,	   ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{3, "VoIP media profile pointer",	2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,	   ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{4, "Signalling code",	            1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_voip_voice_ctp_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_voip_voice_ctp_t omci_voip_voice_ctp_attr_data = {0};

omci_attr_t omci_voip_voice_ctp_attr ={
	(uint8_t *)&omci_voip_voice_ctp_attr_data,
	sizeof(omci_voip_voice_ctp_attr_data),
};

/*******************************************************************************************************************************
9.9.5  VoIP media profile

********************************************************************************************************************************/
static attribute_func_t voipMediaProFaxModeFunc = {
	getVOIPMediaProFaxMode,
	setVOIPMediaProFaxMode
};
static attribute_func_t voipMediaProCodecSele1stFunc = {
	getVOIPMediaProCodecSele1st,
	setVOIPMediaProCodecSele1st
};
static attribute_func_t voipMediaProPktPeriodSele1stFunc = {
	getVOIPMediaProPktPeriodSele1st,
	setVOIPMediaProPktPeriodSele1st
};

static attribute_func_t voipMediaProSlience1stFunc = {
	getVOIPMediaProSlience1st,
	setVOIPMediaProSlience1st
};
static attribute_func_t voipMediaProCodecSele2ndFunc = {
	getVOIPMediaProCodecSele2nd,
	setVOIPMediaProCodecSele2nd
};
static attribute_func_t voipMediaProPktPeriodSele2ndFunc = {
	getVOIPMediaProPktPeriodSele2nd,
	setVOIPMediaProPktPeriodSele2nd
};
static attribute_func_t voipMediaProSlience2ndFunc = {
	getVOIPMediaProSlience2nd,
	setVOIPMediaProSlience2nd
};

static attribute_func_t voipMediaProCodecSele3rdFunc = {
	getVOIPMediaProCodecSele3rd,
	setVOIPMediaProCodecSele3rd
};
static attribute_func_t voipMediaProPktPeriodSele3rdFunc = {
	getVOIPMediaProPktPeriodSele3rd,
	setVOIPMediaProPktPeriodSele3rd
};
static attribute_func_t voipMediaProSlience3rdFunc = {
	getVOIPMediaProSlience3rd,
	setVOIPMediaProSlience3rd
};

static attribute_func_t voipMediaProCodecSele4thFunc = {
	getVOIPMediaProCodecSele4th,
	setVOIPMediaProCodecSele4th
};
static attribute_func_t voipMediaProPktPeriodSele4thFunc = {
	getVOIPMediaProPktPeriodSele4th,
	setVOIPMediaProPktPeriodSele4th
};
static attribute_func_t voipMediaProSlience4thFunc = {
	getVOIPMediaProSlience4th,
	setVOIPMediaProSlience4th
};

static attribute_func_t voipMediaProOOBDtmfFunc = {
	getVOIPMediaProOOBDtmf,
	setVOIPMediaProOOBDtmf
};

omci_attr_dscp_t omci_attr_voip_media_prof_op[]={
	{0, "meId", 						2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "Fax mode",						1,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProFaxModeFunc},
	{2, "Voice serv profile pointer", 	2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "Codec select-1st order",		1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProCodecSele1stFunc},
	{4, "Pkt period select-1st order",	1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProPktPeriodSele1stFunc},
	{5, "Silence -1st order",			1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProSlience1stFunc},
	{6, "Codec select-2nd order",		1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProCodecSele2ndFunc},
	{7, "Pkt period select-2nd order",	1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProPktPeriodSele2ndFunc},
	{8, "Silence -2nd order",			1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProSlience2ndFunc},
	{9, "Codec select-3rd order",		1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProCodecSele3rdFunc},
	{10, "Pkt period select-3rd order",	1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProPktPeriodSele3rdFunc},
	{11, "Silence -3rd order",			1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProSlience3rdFunc},
	{12, "Codec select-4th order",		1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProCodecSele4thFunc},
	{13, "Pkt period select-4th order",	1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProPktPeriodSele4thFunc},
	{14, "Silence -4th order",			1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProSlience4thFunc},
	{15, "OOB DTMF",					1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&voipMediaProOOBDtmfFunc},
	{16, "RTP profile pointer",			2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_voip_media_prof_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_voip_media_prof_t omci_voip_media_prof_attr_data = {0};

omci_attr_t omci_voip_media_prof_attr ={
	(uint8_t *)&omci_voip_media_prof_attr_data,
	sizeof(omci_voip_media_prof_attr_data),
};

/*******************************************************************************************************************************
9.9.6: Voice service profile

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_voice_srv_prof_op[]={
	{ 0, "meID",                            2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 1, "Announcement type",               1, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 2, "Jitter target",                   2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 3, "Jitter buffer max",               2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 4, "Echo cancel ind",                 1, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 5, "PSTN protocol variant",           2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 6, "DTMF digit levels",               2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 7, "DTMF digit duration",             2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 8, "Hook flash minimum time",         2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 9, "Hook flash maximum time",         2, ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 10, "Tone pattern table",             20, ATTR_ACCESS_R_W,                ATTR_FORMAT_TABLE, 		   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 11, "Tone event table",               7, ATTR_ACCESS_R_W,                 ATTR_FORMAT_TABLE, 	       ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 12, "Ringing pattern table",          5, ATTR_ACCESS_R_W,                 ATTR_FORMAT_TABLE, 		   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 13, "Ringing event table",            7, ATTR_ACCESS_R_W,                 ATTR_FORMAT_TABLE, 		   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 14, "Network specific extension ptr",	2, ATTR_ACCESS_R_W_SET_CREATE, 		ATTR_FORMAT_UNSIGNED_INT,  ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, "", 							    0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_voice_srv_prof_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_voice_srv_prof_t omci_voice_srv_prof_attr_data = {0};

omci_attr_t omci_voice_srv_prof_attr ={
	(uint8_t *)&omci_voice_srv_prof_attr_data,
	sizeof(omci_voice_srv_prof_attr_data),
};

/*******************************************************************************************************************************
9.9.7: RTP profile data

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_rtp_prof_op[]={
	{ 0, "meID",                            2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 1, "Local port min",                  2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 2, "Local port max",                  2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 3, "DSCP mark",                       1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 4, "Piggyback events",                1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 5, "Tone events",                     1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 6, "DTMF events",                     1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 7, "CAS events",                      1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 8, "IP host config ptr",				2, ATTR_ACCESS_R_W,					ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, "", 							    0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_rtp_prof_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_rtp_prof_t omci_rtp_prof_attr_data = {0};

omci_attr_t omci_rtp_prof_attr ={
	(uint8_t *)&omci_rtp_prof_attr_data,
	sizeof(omci_rtp_prof_attr_data),
};

/*******************************************************************************************************************************
9.9.8: VoIP application service profile

********************************************************************************************************************************/

static attribute_func_t voipAppSvcProCIDFeaturesFunc = {
	NULL,
	setvoipAppSvcProCIDFeatures
};

static attribute_func_t voipAppSvcProDirectConnectFeatureFunc = {
	NULL,
	setvoipAppSvcProDirectConnectFeature
};

static attribute_func_t voipAppSvcProDirectConnectURIPointerFunc = {
	NULL,
	setvoipAppSvcProDirectConnectURIPointer
};


omci_attr_dscp_t omci_attr_voip_app_srv_prof_op[]={
	{ 0, "meID",                            2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{ 1, "CID feature",                     1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, &voipAppSvcProCIDFeaturesFunc},
	{ 2, "Call waiting feature",            1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{ 3, "Call prog or trans features",     2, ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{ 4, "Call presentation features",      2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{ 5, "Direct connect feature",          1, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, &voipAppSvcProDirectConnectFeatureFunc},
	{ 6, "Direct connect URI pointer",      2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_POINTER, 	  ATTR_FULLY_SUPPORT, &voipAppSvcProDirectConnectURIPointerFunc},
	{ 7, "Brg line agent URI pointer",      2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_POINTER, 	  ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{ 8, "Confence factory URI pointer",    2, ATTR_ACCESS_R_W_SET_CREATE,      ATTR_FORMAT_POINTER, 	  ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{ 9, "Dial tone feature delay or warmline timer",	2, ATTR_ACCESS_R_W,		ATTR_FORMAT_POINTER,	  ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{255, "", 							    0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_voip_app_srv_prof_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_voip_app_srv_prof_t omci_voip_app_srv_prof_attr_data = {0};

omci_attr_t omci_voip_app_srv_prof_attr ={
	(uint8_t *)&omci_voip_app_srv_prof_attr_data,
	sizeof(omci_voip_app_srv_prof_attr_data),
};

/*******************************************************************************************************************************
9.9.10 network dial plan table

********************************************************************************************************************************/
static attribute_func_t netDialPlanTblDialNumberFunc = {
	getNetDialPlanTblDialNumber,
	NULL
};
static attribute_func_t netDialPlanTblDialFormatFunc = {
	NULL,
	setNetDialPlanTblDialFormat
};
static attribute_func_t netDialPlanTblDialTblFunc = {
	NULL, //getNetDialPlanTblDialTbl, no need implent in omci2.0
	setNetDialPlanTblDialTbl
};

omci_attr_dscp_t omci_attr_net_dial_plan_tab_op[]={
	{0, "meId", 					2,	ATTR_ACCESS_R_SET_CREATE,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{1, "Dial plan number",			2,	ATTR_ACCESS_R, 				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &netDialPlanTblDialNumberFunc},
	{2, "Dial plan tbl max size",	2,	ATTR_ACCESS_R_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{3, "Critical dial timeout",	2,	ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{4, "Partial dial timeout",		2,	ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{5, "Dial plan format",			1,	ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &netDialPlanTblDialFormatFunc},
	{6, "Dial plan tbl",			30,	ATTR_ACCESS_R_W,			ATTR_FORMAT_TABLE,			ATTR_FULLY_SUPPORT,	 &netDialPlanTblDialTblFunc},
	{255, "", 						0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_net_dial_plan_tab_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
	//?? getnext
};

omci_net_dial_plan_tab_t omci_net_dial_plan_tab_attr_data = {0};

omci_attr_t omci_net_dial_plan_tab_attr ={
	(uint8_t *)&omci_net_dial_plan_tab_attr_data,
	sizeof(omci_net_dial_plan_tab_attr_data),
};

/*******************************************************************************************************************************
9.9.11: VoIP line status

********************************************************************************************************************************/
static attribute_func_t VoIPLineStatusCodecsUsedFunc = {
	getVoIPStatusDataCodecsUsed,
	NULL
};
static attribute_func_t VoIPLineStatusVoiceServerStatusFunc = {
	getVoIPLineStatusVoiceServerStatus,
	NULL
};
static attribute_func_t VoIPLineStatusPortSessionTypeFunc = {
	getVoIPLineStatusPortSessionType,
	NULL
};
static attribute_func_t VoIPLineStatusCall1PacketPeriodFunc = {
	getVoIPLineStatusCall1PacketPeriod,
	NULL
};
static attribute_func_t VoIPLineStatusCall2PacketPeriodFunc = {
	getVoIPLineStatusCall2PacketPeriod,
	NULL
};
static attribute_func_t VoIPLineStateFunc = {
	getVoIPLineState,
	NULL
};


omci_attr_dscp_t omci_attr_voip_line_status_op[]={
	{0, "meId",							2,	ATTR_ACCESS_R,	ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "voip codec used",				2,	ATTR_ACCESS_R,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&VoIPLineStatusCodecsUsedFunc},
	{2, "voip voice server status",		1,	ATTR_ACCESS_R,	ATTR_FORMAT_ENUM,           ATTR_FULLY_SUPPORT,	&VoIPLineStatusVoiceServerStatusFunc},
	{3, "voip port session type",		1,	ATTR_ACCESS_R,	ATTR_FORMAT_ENUM,			ATTR_FULLY_SUPPORT,	&VoIPLineStatusPortSessionTypeFunc},
	{4, "voip call 1 packet period",	2,	ATTR_ACCESS_R,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&VoIPLineStatusCall1PacketPeriodFunc},
	{5, "voip call 2 packet period",	2,	ATTR_ACCESS_R,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&VoIPLineStatusCall2PacketPeriodFunc},
	{6, "voip call 1 dest addr",		25,	ATTR_ACCESS_R,	ATTR_FORMAT_STRING,		    ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{7, "voip call 2 dest addr",		25, ATTR_ACCESS_R,	ATTR_FORMAT_STRING,		    ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{8, "voip line state",				1, ATTR_ACCESS_R,	ATTR_FORMAT_UNSIGNED_INT, 	ATTR_FULLY_SUPPORT, &VoIPLineStateFunc},
	{9, "emgergency call status",		1, ATTR_ACCESS_R,	ATTR_FORMAT_UNSIGNED_INT, 	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_voip_line_status_op ={
	NULL,
	NULL,
	NULL,
	omci_me_general_get_op,
	NULL,
};

omci_voip_line_status_t omci_voip_line_status_attr_data = {0};

omci_attr_t omci_voip_line_status_attr ={
	(uint8_t *)&omci_voip_line_status_attr_data,
	sizeof(omci_voip_line_status_attr_data),
};

/*******************************************************************************************************************************
9.9.12: Call Control performance monitoring history data

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_call_ctl_pm_hist_op[]={
	{ 0, "meID",                       2, ATTR_ACCESS_R_SET_CREATE,   ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc },
	{ 1, "interval end time",          1, ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 2, "Threshold data 1/2 id",      2, ATTR_ACCESS_R_W_SET_CREATE, ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 3, "Call setup failures",        4, ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 4, "Call setup timer",           4, ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 5, "Call terminate failures",    4, ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 6, "Analog port releases",       4, ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{ 7, "Analog port off-hook timer", 4, ATTR_ACCESS_R,              ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, "", 						   0,  0,                              0,                          0,                  NULL}
};

int get_call_ctrl_data(CallCtrlPmcounters_t *data, uint16_t instId)
{
    #define CALL_CTRL_NODE_NUM      5
    uint32_t *val = NULL;
    uint16_t entryIndex = 0;
    uint8_t index = 0;
    char tempBuffer[64] = {0};
	char nodeName[32] = {0};
	char *g_call_ctrl_node[CALL_CTRL_NODE_NUM] = {"CallsSetUpFailed", "MaxCallSetUpTime", "CallsDropped", "OffHookNoDialed", "SeizeMin"};

	if(data == NULL)
	{
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    /* portId is ME instrance Id , for RTP PM history data, the instranceId is linked to PPTP POTS UNI,  which is ((POTS_SLOT<<8) | i) */
    entryIndex = (instId & 0xFF) -1;

	memset(nodeName, 0, sizeof(nodeName));
    sprintf(nodeName, "InfoVoIP_Entry%d", entryIndex);
    
	memset(data, 0, sizeof(CallCtrlPmcounters_t));
	
	val = (uint32_t *)data;
	for(index = 0; index < CALL_CTRL_NODE_NUM;index++,val++)
    {
    	/* get rtp error packet */
	    memset(tempBuffer, 0, sizeof(tempBuffer));
	    if(omci_tcapi_nget(nodeName,g_call_ctrl_node[index], tempBuffer, sizeof(tempBuffer)) != 0)
        {
	        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]tcapi get fail.\n",__FUNCTION__,__LINE__);
			continue;
	    }    
	    *val = atoi(tempBuffer);
    }
	
   return 0;
}

int get_call_ctrl_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    CallCtrlPmcounters_t call_ctrl ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_call_ctrl_data(&call_ctrl, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_call_ctrl_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.call_ctl_pm.intervalEndTime = pmIntervalTimes;
    	pm_list->pm_data.call_ctl_pm.callSetupFail = call_ctrl.SetupFailure - pm_list->pm_prev_data.callCtrl.SetupFailure;
    	pm_list->pm_data.call_ctl_pm.callSetupTimer = call_ctrl.SetupTimer - pm_list->pm_prev_data.callCtrl.SetupTimer;
    	pm_list->pm_data.call_ctl_pm.callTerminateFail = call_ctrl.TerminateFailure - pm_list->pm_prev_data.callCtrl.TerminateFailure;
        pm_list->pm_data.call_ctl_pm.analogPortReleases = call_ctrl.PortRelease - pm_list->pm_prev_data.callCtrl.PortRelease;
        pm_list->pm_data.call_ctl_pm.analogPortOffhookTimer = call_ctrl.PortOffhookTimer - pm_list->pm_prev_data.callCtrl.PortOffhookTimer;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->callSetupFail = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.call_ctl_pm.callSetupFail);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->callSetupTimer = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.call_ctl_pm.callSetupTimer);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->callTerminateFail = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.call_ctl_pm.callTerminateFail);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->analogPortReleases = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.call_ctl_pm.analogPortReleases);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->analogPortOffhookTimer = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.call_ctl_pm.analogPortOffhookTimer);
        
    }

    memcpy(&pm_list->pm_prev_data.callCtrl, &call_ctrl, sizeof(CallCtrlPmcounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->callSetupFail = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.callCtrl.SetupFailure);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->callSetupTimer = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.callCtrl.SetupTimer);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->callTerminateFail = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.callCtrl.TerminateFailure);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->analogPortReleases = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.callCtrl.PortRelease);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->analogPortOffhookTimer = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.callCtrl.PortOffhookTimer);
        
    return 0;
}




int omci_me_call_ctrl_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_call_ctl_pm_hist_ptr call_ctrl_pm_new = NULL;
    CallCtrlPmcounters_t call_ctrl ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    call_ctrl_pm_new = (omci_call_ctl_pm_hist_ptr)me_info->attributes;
    if(call_ctrl_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_call_ctrl_data(&call_ctrl, me_info->inst_id) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_call_ctrl_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	call_ctrl_pm_new->intervalEndTime = pmIntervalTimes;
	call_ctrl_pm_new->callSetupFail = call_ctrl.SetupFailure;
	call_ctrl_pm_new->callSetupTimer = call_ctrl.SetupTimer;
	call_ctrl_pm_new->callTerminateFail = call_ctrl.TerminateFailure;
    call_ctrl_pm_new->analogPortReleases = call_ctrl.PortRelease;
    call_ctrl_pm_new->analogPortOffhookTimer = call_ctrl.PortOffhookTimer;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->callSetupFail = 0x%x\n",__FUNCTION__,__LINE__, call_ctrl_pm_new->callSetupFail);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->callSetupTimer = 0x%x\n",__FUNCTION__,__LINE__, call_ctrl_pm_new->callSetupTimer);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->callTerminateFail = 0x%x\n",__FUNCTION__,__LINE__, call_ctrl_pm_new->callTerminateFail);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->analogPortReleases = 0x%x\n",__FUNCTION__,__LINE__, call_ctrl_pm_new->analogPortReleases);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->analogPortOffhookTimer = 0x%x\n",__FUNCTION__,__LINE__,call_ctrl_pm_new->analogPortOffhookTimer);

    return 0;
}


int omci_me_call_ctrl_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ CALL_CTRL_PM_HISTORY_DATA_TCA_NUM = 5};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[CALL_CTRL_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[CALL_CTRL_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[CALL_CTRL_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 3, 4};
    tca_notify_info_t tca_info = {0};
    CallCtrlPmcounters_t call_ctrl ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_call_ctrl_data(&call_ctrl, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_call_ctrl_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0] = call_ctrl.SetupFailure - pm_list->pm_prev_data.callCtrl.SetupFailure;
	currentData[1] = call_ctrl.SetupTimer - pm_list->pm_prev_data.callCtrl.SetupTimer;
	currentData[2] = call_ctrl.TerminateFailure - pm_list->pm_prev_data.callCtrl.TerminateFailure;
    currentData[3] = call_ctrl.PortRelease - pm_list->pm_prev_data.callCtrl.PortRelease;
    currentData[4] = call_ctrl.PortOffhookTimer - pm_list->pm_prev_data.callCtrl.PortOffhookTimer;
    

    for(i = 0; i < CALL_CTRL_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}

omci_me_func_t omci_me_call_ctl_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_call_ctrl_pm_history_get_curr_op,
};

omci_call_ctl_pm_hist_t omci_call_ctl_pm_hist_attr_data = {0};

omci_attr_t omci_call_ctl_pm_hist_attr ={
	(uint8_t *)&omci_call_ctl_pm_hist_attr_data,
	sizeof(omci_call_ctl_pm_hist_attr_data),
};


/*******************************************************************************************************************************
9.9.13: Rtp performance monitoring history data

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_rtp_pm_hist_op[]={
	{0, "meId",							2,	ATTR_ACCESS_R_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "interval end time",			1,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "threshold data 1/2 id",		2,	ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "rtp errors",           		4,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{4, "packet loss",              	4,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{5, "maximum jitter",           	4,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{6, "maximum time between RTCP", 	4,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{7, "buffer underflows",            4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{8, "buffer overflows",             4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

int get_rtp_data(RTPDataPmcounters_t *data, uint16_t instId)
{
    uint16_t entryIndex = 0;
    char tempBuffer[64] = {0};
    char nodeName[32] = {0};

	if(data == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pointer is NULL\n",__FUNCTION__,__LINE__);
        return -1;
	}  

    memset(nodeName, 0, sizeof(nodeName));
    sprintf(nodeName, "InfoVoIP_Entry%d", entryIndex);
    /* get rtp error packet */
    memset(tempBuffer, 0, sizeof(tempBuffer));
    if(omci_tcapi_nget(nodeName, OMCI_RTP_PM_RTPERROR, tempBuffer,sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] tcapi get fail\n",__FUNCTION__,__LINE__);
    }    
    data->RtpErrors = atoi(tempBuffer);
    
    /* get packet loss rate */
    memset(tempBuffer, 0, sizeof(tempBuffer));
    if(omci_tcapi_nget(nodeName, OMCI_RTP_PM_PacketLoss, tempBuffer, sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] tcapi get fail\n",__FUNCTION__,__LINE__);
    }    
    data->PacketLoss = atoi(tempBuffer);

    /* get max jitter */
    memset(tempBuffer, 0, sizeof(tempBuffer));
    if(omci_tcapi_nget(nodeName, OMCI_RTP_PM_MaxJitter, tempBuffer, sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] tcapi get fail\n",__FUNCTION__,__LINE__);
    }
    data->MaxJitter = RTP_TIMESTAMP_UNIT*atoi(tempBuffer);

    /* get max RTC interval */
    memset(tempBuffer, 0, sizeof(tempBuffer));
    if(omci_tcapi_nget(nodeName, OMCI_RTP_PM_MaxTimeBetRTCP, tempBuffer, sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] tcapi get fail\n",__FUNCTION__,__LINE__);
    }
    data->MaxTimeBetRTCP = atoi(tempBuffer);

    /* get buf under flow */
    memset(tempBuffer, 0, sizeof(tempBuffer));
    if(omci_tcapi_nget(nodeName, OMCI_RTP_PM_BUFUNDERFLOW, tempBuffer,sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] tcapi get fail\n",__FUNCTION__,__LINE__);
    }
    data->BufferUnderflows = atoi(tempBuffer);

    /* get buf over flow */
    memset(tempBuffer, 0, sizeof(tempBuffer));
    if(omci_tcapi_nget(nodeName, OMCI_RTP_PM_BUFOVERFLOW, tempBuffer, sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] tcapi get fail\n",__FUNCTION__,__LINE__);
    }
    data->BufferOverflows = atoi(tempBuffer);

    return 0;

}

int get_rtp_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    RTPDataPmcounters_t rtp ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_rtp_data(&rtp, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_rtp_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.rtp_pm.intervalEndTime = pmIntervalTimes;
    	pm_list->pm_data.rtp_pm.rtpErrors = rtp.RtpErrors - pm_list->pm_prev_data.rtp.RtpErrors;
    	pm_list->pm_data.rtp_pm.pktLoss = rtp.PacketLoss - pm_list->pm_prev_data.rtp.PacketLoss;
    	pm_list->pm_data.rtp_pm.maxJitter = rtp.MaxJitter - pm_list->pm_prev_data.rtp.MaxJitter;
        pm_list->pm_data.rtp_pm.maxTimerBwtRtcpPkts = rtp.MaxTimeBetRTCP- pm_list->pm_prev_data.rtp.MaxTimeBetRTCP;
        pm_list->pm_data.rtp_pm.bufUnderflows = rtp.BufferUnderflows - pm_list->pm_prev_data.rtp.BufferUnderflows;
        pm_list->pm_data.rtp_pm.bufOverflows= rtp.BufferOverflows - pm_list->pm_prev_data.rtp.BufferOverflows;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rtpErrors = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.rtp_pm.rtpErrors);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->pktLoss = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.rtp_pm.pktLoss);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->maxJitter = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.rtp_pm.maxJitter);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->maxTimerBwtRtcpPkts = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.rtp_pm.maxTimerBwtRtcpPkts);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->bufUnderflows = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.rtp_pm.bufUnderflows);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->bufOverflows = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.rtp_pm.bufOverflows);
    }

    memcpy(&pm_list->pm_prev_data.rtp, &rtp, sizeof(RTPDataPmcounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rtpErrors = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.rtp.RtpErrors);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->pktLoss = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.rtp.PacketLoss);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->maxJitter = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.rtp.MaxJitter);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->maxTimerBwtRtcpPkts = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.rtp.MaxTimeBetRTCP);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->bufUnderflows = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.rtp.BufferUnderflows);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->bufOverflows = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.rtp.BufferOverflows);
        
    return 0;
}




int omci_me_rtp_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_rtp_pm_hist_ptr rtp_pm_new = NULL;
    RTPDataPmcounters_t rtp ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    rtp_pm_new = (omci_rtp_pm_hist_ptr)me_info->attributes;
    if(rtp_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_rtp_data(&rtp, me_info->inst_id) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_rtp_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	rtp_pm_new->intervalEndTime = pmIntervalTimes;
	rtp_pm_new->rtpErrors = rtp.RtpErrors;
	rtp_pm_new->pktLoss= rtp.PacketLoss;
	rtp_pm_new->maxJitter= rtp.MaxJitter;
	rtp_pm_new->maxTimerBwtRtcpPkts= rtp.MaxTimeBetRTCP;
	rtp_pm_new->bufUnderflows= rtp.BufferUnderflows;
	rtp_pm_new->bufOverflows= rtp.BufferOverflows;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rtpErrors = 0x%x\n",__FUNCTION__,__LINE__, rtp_pm_new->rtpErrors);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->pktLoss = 0x%x\n",__FUNCTION__,__LINE__, rtp_pm_new->pktLoss);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->maxJitter = 0x%x\n",__FUNCTION__,__LINE__, rtp_pm_new->maxJitter);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->maxTimerBwtRtcpPkts = 0x%x\n",__FUNCTION__,__LINE__, rtp_pm_new->maxTimerBwtRtcpPkts);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->bufUnderflows = 0x%x\n",__FUNCTION__,__LINE__,rtp_pm_new->bufUnderflows);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->bufOverflows = 0x%x\n",__FUNCTION__,__LINE__,rtp_pm_new->bufOverflows);

    return 0;
}


int omci_me_rtp_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ RTP_PM_HISTORY_DATA_TCA_NUM = 6};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[RTP_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[RTP_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[RTP_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 3, 4, 5};
    tca_notify_info_t tca_info = {0};
    RTPDataPmcounters_t rtp ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_rtp_data(&rtp, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_rtp_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    /*monitor 15min interval tca attribute value*/
	currentData[0] = rtp.RtpErrors - pm_list->pm_prev_data.rtp.RtpErrors;
	currentData[1] = rtp.PacketLoss - pm_list->pm_prev_data.rtp.PacketLoss;
	currentData[2] = rtp.MaxJitter - pm_list->pm_prev_data.rtp.MaxJitter;
    currentData[3] = rtp.MaxTimeBetRTCP - pm_list->pm_prev_data.rtp.MaxTimeBetRTCP;
    currentData[4] = rtp.BufferUnderflows - pm_list->pm_prev_data.rtp.BufferUnderflows;
    currentData[5] = rtp.BufferOverflows - pm_list->pm_prev_data.rtp.BufferOverflows;
    

    for(i = 0; i < RTP_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i < 4 ? i : (i+1)]; /*threshold value is 1, 2, 3, 4, 6, 7*/
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_rtp_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_rtp_pm_history_get_curr_op,
};

omci_rtp_pm_hist_t omci_rtp_pm_hist_attr_data = {0};

omci_attr_t omci_rtp_pm_hist_attr ={
	(uint8_t *)&omci_rtp_pm_hist_attr_data,
	sizeof(omci_rtp_pm_hist_attr_data),
};


/*******************************************************************************************************************************
9.9.14: SIP agent performance monitoring history data

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_sip_agent_pm_hist_op[]={
	{0, "meId",							2,	ATTR_ACCESS_R_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "interval end time",			1,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "threshold data 1/2 id",		2,	ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "transactions",		            4,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{4, "rx invite reqs",               4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{5, "rx invite retrans",            4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{6, "rx noninvite reqs",            4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{7, "rx noninvite retrans",         4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{8, "rx response",                  4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{9, "rx response retransmissions",  4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{10, "tx invite reqs",              4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{11, "tx invite retrans",           4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{12, "tx noninvite reqs",           4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{13, "tx noninvite retrans",        4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{14, "tx response",                 4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{15, "tx response retransmissions", 4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

uint32_t SipAgentPMInfo(char * attr)
{
    char nodeName[32] = {0};
    char tempBuffer[64] = {0};
    int val = 0;
    
    if(attr == NULL)
	{
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pointer is NULL\n",__FUNCTION__,__LINE__);
        return -1;
    }  

    strcpy(nodeName, "InfoVoIP_Common");

    if(omci_tcapi_nget(nodeName, attr, tempBuffer,sizeof(tempBuffer)) != 0){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  tcapi get fail %s = %d\n",__FUNCTION__,__LINE__, attr,val);
        return val;
    }  
    val = strtoul(tempBuffer,0,0);
    return val;
}


int get_sip_agent_data(SipAgentPmcounters_s_t *data, uint16_t instId)
{

    if(data == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pointer is NULL\n",__FUNCTION__,__LINE__);
        return -1;
    }  
    

    data->Transactions = SipAgentPMInfo("Transactions");
    data->RxInviteReqs = SipAgentPMInfo("RxInviteReqs");
    data->RxInviteRetrans = SipAgentPMInfo("RxInviteRetrans");
    data->RxNoninviteReqs = SipAgentPMInfo("RxNonInviteReqs");
    data->RxNoninviteRetrans = SipAgentPMInfo("RxNonInviteRetrans");
    data->RxResponse = SipAgentPMInfo("RxResponse");
    data->RxResponseRetransmissions = SipAgentPMInfo("RxResponseRetrans");
    data->TxInviteReqs = SipAgentPMInfo("TxInviteReqs");
    data->TxInviteRetrans = SipAgentPMInfo("TxInviteRetrans");
    data->TxNonInviteReqs = SipAgentPMInfo("TxNonInviteReqs");
    data->TxNonInviteRetrans = SipAgentPMInfo("TxNonInviteRetrans");
    data->TxResponse = SipAgentPMInfo("TxResponse");
    data->TxResponseRetransmissions = SipAgentPMInfo("TxResponseRetrans");

    

    return 0;
}

int get_sip_agent_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    SipAgentPmcounters_s_t sip_agent ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_sip_agent_data(&sip_agent, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_sip_agent_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.sip_agent_pm.intervalEndTime = pmIntervalTimes;
    	pm_list->pm_data.sip_agent_pm.transactions = sip_agent.Transactions - pm_list->pm_prev_data.sipAgent.Transactions;
    	pm_list->pm_data.sip_agent_pm.rxInviteReqs= sip_agent.RxInviteReqs - pm_list->pm_prev_data.sipAgent.RxInviteReqs;
    	pm_list->pm_data.sip_agent_pm.rxInviteRetrans= sip_agent.RxInviteRetrans - pm_list->pm_prev_data.sipAgent.RxInviteRetrans;
        pm_list->pm_data.sip_agent_pm.rxNoninviteReqs= sip_agent.RxNoninviteReqs - pm_list->pm_prev_data.sipAgent.RxNoninviteReqs;
        pm_list->pm_data.sip_agent_pm.rxNoninviteRetrans= sip_agent.RxNoninviteRetrans - pm_list->pm_prev_data.sipAgent.RxNoninviteRetrans;
        pm_list->pm_data.sip_agent_pm.rxReponse= sip_agent.RxResponse - pm_list->pm_prev_data.sipAgent.RxResponse;
        pm_list->pm_data.sip_agent_pm.rxReponseRetrans= sip_agent.RxResponseRetransmissions - pm_list->pm_prev_data.sipAgent.RxResponseRetransmissions;
    	pm_list->pm_data.sip_agent_pm.txInviteReqs= sip_agent.TxInviteReqs - pm_list->pm_prev_data.sipAgent.TxInviteReqs;
    	pm_list->pm_data.sip_agent_pm.txInviteRetrans= sip_agent.TxInviteRetrans - pm_list->pm_prev_data.sipAgent.TxInviteRetrans;
        pm_list->pm_data.sip_agent_pm.txNoninviteReqs= sip_agent.TxNonInviteReqs - pm_list->pm_prev_data.sipAgent.TxNonInviteReqs;
        pm_list->pm_data.sip_agent_pm.txNoninviteRetrans= sip_agent.TxNonInviteRetrans - pm_list->pm_prev_data.sipAgent.TxNonInviteRetrans;
        pm_list->pm_data.sip_agent_pm.txReponse= sip_agent.TxResponse - pm_list->pm_prev_data.sipAgent.TxResponse;
        pm_list->pm_data.sip_agent_pm.txReponseRetrans= sip_agent.TxResponseRetransmissions - pm_list->pm_prev_data.sipAgent.TxResponseRetransmissions;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->transactions = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.transactions);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rxInviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.rxInviteReqs);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rxInviteRetrans = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.rxInviteRetrans);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rxNoninviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.rxNoninviteReqs);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rxNoninviteRetrans = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.sip_agent_pm.rxNoninviteRetrans);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rxReponse = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.sip_agent_pm.rxReponse);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rxReponseRetrans = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.rxReponseRetrans);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->txInviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.txInviteReqs);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->txInviteRetrans = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.txInviteRetrans);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->txNoninviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_agent_pm.txNoninviteReqs);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->txNoninviteRetrans = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.sip_agent_pm.txNoninviteRetrans);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->txReponse = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.sip_agent_pm.txReponse);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->txReponseRetrans = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.sip_agent_pm.txReponseRetrans);
    }

    memcpy(&pm_list->pm_prev_data.sipAgent, &sip_agent, sizeof(SipAgentPmcounters_s_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transactions = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.Transactions);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxInviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.RxInviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxInviteRetrans = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.RxInviteRetrans);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxNoninviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.RxNoninviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxNoninviteRetrans = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.sipAgent.RxNoninviteRetrans);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxReponse = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.sipAgent.RxResponse);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxReponseRetrans = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.RxResponseRetransmissions);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txInviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.TxInviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txInviteRetrans = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.TxInviteRetrans);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txNoninviteReqs = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipAgent.TxNonInviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txNoninviteRetrans = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.sipAgent.TxNonInviteRetrans);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txReponse = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.sipAgent.TxResponse);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txReponseRetrans = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.sipAgent.TxResponseRetransmissions);
        
    return 0;
}

int omci_me_sip_agent_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_sip_agent_pm_hist_ptr sip_agent_pm_new = NULL;
    SipAgentPmcounters_s_t sip_agent ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    sip_agent_pm_new = (omci_sip_agent_pm_hist_ptr)me_info->attributes;
    if(sip_agent_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_sip_agent_data(&sip_agent, me_info->inst_id) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_sip_agent_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	sip_agent_pm_new->intervalEndTime = pmIntervalTimes;
	sip_agent_pm_new->transactions = sip_agent.Transactions;
	sip_agent_pm_new->rxInviteReqs= sip_agent.RxInviteReqs;
	sip_agent_pm_new->rxInviteRetrans= sip_agent.RxInviteRetrans;
    sip_agent_pm_new->rxNoninviteReqs= sip_agent.RxNoninviteReqs;
    sip_agent_pm_new->rxNoninviteRetrans= sip_agent.RxNoninviteRetrans;
    sip_agent_pm_new->rxReponse= sip_agent.RxResponse;
    sip_agent_pm_new->rxReponseRetrans= sip_agent.RxResponseRetransmissions;
	sip_agent_pm_new->txInviteReqs= sip_agent.TxInviteReqs;
	sip_agent_pm_new->txInviteRetrans= sip_agent.TxInviteRetrans;
    sip_agent_pm_new->txNoninviteReqs= sip_agent.TxNonInviteReqs;
    sip_agent_pm_new->txNoninviteRetrans= sip_agent.TxNonInviteRetrans;
    sip_agent_pm_new->txReponse= sip_agent.TxResponse;
    sip_agent_pm_new->txReponseRetrans= sip_agent.TxResponseRetransmissions;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transactions = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->transactions);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxInviteReqs = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->rxInviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxInviteRetrans = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->rxInviteRetrans);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxNoninviteReqs = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->rxNoninviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxNoninviteRetrans = 0x%x\n",__FUNCTION__,__LINE__,sip_agent_pm_new->rxNoninviteRetrans);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxReponse = 0x%x\n",__FUNCTION__,__LINE__,sip_agent_pm_new->rxReponse);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rxReponseRetrans = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->rxReponseRetrans);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txInviteReqs = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->txInviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txInviteRetrans = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->txInviteRetrans);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txNoninviteReqs = 0x%x\n",__FUNCTION__,__LINE__, sip_agent_pm_new->txNoninviteReqs);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txNoninviteRetrans = 0x%x\n",__FUNCTION__,__LINE__,sip_agent_pm_new->txNoninviteRetrans);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txReponse = 0x%x\n",__FUNCTION__,__LINE__,sip_agent_pm_new->txReponse);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->txReponseRetrans = 0x%x\n",__FUNCTION__,__LINE__,sip_agent_pm_new->txReponseRetrans);

    return 0;
}


int omci_me_sip_agent_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ SIP_AGENT_PM_HISTORY_DATA_TCA_NUM = 6};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[SIP_AGENT_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[SIP_AGENT_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[SIP_AGENT_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 3, 4, 5};
    tca_notify_info_t tca_info = {0};
    SipAgentPmcounters_s_t sip_agent ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_sip_agent_data(&sip_agent, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_sip_agent_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0] = sip_agent.RxInviteReqs - pm_list->pm_prev_data.sipAgent.RxInviteReqs;
	currentData[1] = sip_agent.RxInviteRetrans - pm_list->pm_prev_data.sipAgent.RxInviteRetrans;
	currentData[2] = sip_agent.RxNoninviteReqs - pm_list->pm_prev_data.sipAgent.RxNoninviteReqs;
    currentData[3] = sip_agent.RxNoninviteRetrans - pm_list->pm_prev_data.sipAgent.RxNoninviteRetrans;
    currentData[4] = sip_agent.RxResponse - pm_list->pm_prev_data.sipAgent.RxResponse;
    currentData[5] = sip_agent.RxResponseRetransmissions - pm_list->pm_prev_data.sipAgent.RxResponseRetransmissions;
    

    for(i = 0; i < SIP_AGENT_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_sip_agent_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_sip_agent_pm_history_get_curr_op,
};

omci_sip_agent_pm_hist_t omci_sip_agent_pm_hist_attr_data = {0};

omci_attr_t omci_sip_agent_pm_hist_attr ={
	(uint8_t *)&omci_sip_agent_pm_hist_attr_data,
	sizeof(omci_sip_agent_pm_hist_attr_data),
};


/*******************************************************************************************************************************
9.9.15: SIP call initation performance monitoring history data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_sip_call_init_pm_hist_op[]={
	{0, "meId",							    2,	ATTR_ACCESS_R_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "interval end time",			    1,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "threshold data 1/2 id",		    2,	ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "failed to connect counter",	    4,	ATTR_ACCESS_R,	                ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{4, "failed to validate counter",       4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{5, "timeout counter",                  4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{6, "failure received counter",         4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{7, "failed to authenticate counter",   4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,  &generalAttrFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

uint32_t SipCallInitPMInfo(char * attr)
{
    int voip_num = 1;
    char nodeName[32] = {0};
    char tempBuffer[64] = {0};
    int i = 0;
    int val = 0;
    
    if(attr == NULL)
        return -1;

    strcpy(nodeName, "VoIPSysParam_Common");

    if(omci_tcapi_nget(nodeName, "SC_SYS_CFG_MAX_LINE", tempBuffer, sizeof(tempBuffer)) == 0){
        voip_num = atoi(tempBuffer);
    }
 
    for (i = 0 ;i < voip_num; i++)
    {
        memset(nodeName, 0, sizeof(nodeName));
        snprintf(nodeName, sizeof(nodeName), "InfoVoIP_%s%x", "Entry", i);  

        if(omci_tcapi_nget(nodeName, attr, tempBuffer, sizeof(tempBuffer)) != 0){
            omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  tcapi get fail %s = %d\n",__FUNCTION__,__LINE__, attr,val);
            return val;
        }  
        val += strtoul(tempBuffer,0,0);
    }
    return val;
}


int get_sip_call_init_data(SipCallInitPmcounters_t *data, uint16_t instId)
{
    
    if(data == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pointer is NULL\n",__FUNCTION__,__LINE__);
        return -1;
    }  

    data->FailedToConnect = SipCallInitPMInfo("FailToConnect");
    data->FailedToValidate = SipCallInitPMInfo("FailToValidate");
    data->Timeout = SipCallInitPMInfo("FailTimeout");
    data->FailureReceived = SipCallInitPMInfo("FailureRecv");
    data->FailedToAuthenticate = SipCallInitPMInfo("FailToAuth");

    return 0;
}

int get_sip_call_init_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    SipCallInitPmcounters_t sip_call ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_sip_call_init_data(&sip_call, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_rtp_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.sip_call_init_pm.intervalEndTime = pmIntervalTimes;
    	pm_list->pm_data.sip_call_init_pm.failedToConnectCnt= sip_call.FailedToConnect - pm_list->pm_prev_data.sipCall.FailedToConnect;
    	pm_list->pm_data.sip_call_init_pm.failedToValidateCnt= sip_call.FailedToValidate - pm_list->pm_prev_data.sipCall.FailedToValidate;
    	pm_list->pm_data.sip_call_init_pm.timeoutCnt= sip_call.Timeout - pm_list->pm_prev_data.sipCall.Timeout;
        pm_list->pm_data.sip_call_init_pm.failureRxCnt= sip_call.FailureReceived - pm_list->pm_prev_data.sipCall.FailureReceived;
        pm_list->pm_data.sip_call_init_pm.failureToAuthenCnt= sip_call.FailedToAuthenticate - pm_list->pm_prev_data.sipCall.FailedToAuthenticate;
        
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->failedToConnectCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_call_init_pm.failedToConnectCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->failedToValidateCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_call_init_pm.failedToValidateCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->timeoutCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_call_init_pm.timeoutCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->failureRxCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.sip_call_init_pm.failureRxCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->failureToAuthenCnt = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.sip_call_init_pm.failureToAuthenCnt);
    }

    memcpy(&pm_list->pm_prev_data.sipCall, &sip_call, sizeof(SipCallInitPmcounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failedToConnectCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipCall.FailedToConnect);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failedToValidateCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipCall.FailedToValidate);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->timeoutCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipCall.Timeout);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failureRxCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.sipCall.FailureReceived);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failureToAuthenCnt = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.sipCall.FailedToAuthenticate);
        
    return 0;
}




int omci_me_sip_call_init_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_sip_call_init_pm_hist_ptr sip_call_init_pm_new = NULL;
    SipCallInitPmcounters_t sip_call ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    sip_call_init_pm_new = (omci_sip_call_init_pm_hist_ptr)me_info->attributes;
    if(sip_call_init_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_sip_call_init_data(&sip_call, me_info->inst_id) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_rtp_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	sip_call_init_pm_new->intervalEndTime = pmIntervalTimes;
	sip_call_init_pm_new->failedToConnectCnt= sip_call.FailedToConnect;
	sip_call_init_pm_new->failedToValidateCnt= sip_call.FailedToValidate;
	sip_call_init_pm_new->timeoutCnt= sip_call.Timeout;
    sip_call_init_pm_new->failureRxCnt= sip_call.FailureReceived;
    sip_call_init_pm_new->failureToAuthenCnt= sip_call.FailedToAuthenticate;
    
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failedToConnectCnt = 0x%x\n",__FUNCTION__,__LINE__, sip_call_init_pm_new->failedToConnectCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failedToValidateCnt = 0x%x\n",__FUNCTION__,__LINE__, sip_call_init_pm_new->failedToValidateCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->timeoutCnt = 0x%x\n",__FUNCTION__,__LINE__, sip_call_init_pm_new->timeoutCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failureRxCnt = 0x%x\n",__FUNCTION__,__LINE__, sip_call_init_pm_new->failureRxCnt);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->failureToAuthenCnt = 0x%x\n",__FUNCTION__,__LINE__,sip_call_init_pm_new->failureToAuthenCnt);

    return 0;
}


int omci_me_sip_call_init_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ SIP_CALL_INIT_PM_HISTORY_DATA_TCA_NUM = 5};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[SIP_CALL_INIT_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[SIP_CALL_INIT_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[SIP_CALL_INIT_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 3, 4};
    tca_notify_info_t tca_info = {0};
    SipCallInitPmcounters_t sip_call ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(get_sip_call_init_data(&sip_call, pm_list->instId) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_rtp_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0] = sip_call.FailedToConnect - pm_list->pm_prev_data.sipCall.FailedToConnect;
	currentData[1] = sip_call.FailedToValidate - pm_list->pm_prev_data.sipCall.FailedToValidate;
	currentData[2] = sip_call.Timeout - pm_list->pm_prev_data.sipCall.Timeout;
    currentData[3] = sip_call.FailureReceived - pm_list->pm_prev_data.sipCall.FailureReceived;
    currentData[4] = sip_call.FailedToAuthenticate - pm_list->pm_prev_data.sipCall.FailedToAuthenticate;
    

    for(i = 0; i < SIP_CALL_INIT_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_sip_call_init_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_sip_call_init_pm_history_get_curr_op,
};

omci_sip_call_init_pm_hist_t omci_sip_call_init_pm_hist_attr_data = {0};

omci_attr_t omci_sip_call_init_pm_hist_attr ={
	(uint8_t *)&omci_sip_call_init_pm_hist_attr_data,
	sizeof(omci_sip_call_init_pm_hist_attr_data),
};


/*******************************************************************************************************************************
9.9.16 MGC config data

********************************************************************************************************************************/

static attribute_func_t mgcCfgDataPriMGCFunc = {
	NULL,
	setMGCCfgDataPriMGC
};
static attribute_func_t mgcCfgDataSecMGCFunc = {
	NULL,
	setMGCCfgDataSecMGC
};

static attribute_func_t mgcCfgDataDevIdFunc = {
	getMGCCfgDataDevId,
	setMGCCfgDataDevId
};

omci_attr_dscp_t omci_attr_mgc_cfg_data_op[]={
	{0, "meId", 				2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{1, "Primary MGC",			2,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT, &mgcCfgDataPriMGCFunc},
	{2, "Secondary MGC",		2,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT, &mgcCfgDataSecMGCFunc},
	{3, "TCP-UDP pointer",		2,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{4, "Version", 				1,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{5, "Message format",		1,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{6, "Max retry time",		2,	ATTR_ACCESS_R_W,			 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{7, "Max retry attempts",	2,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{8, "service change delay",	2,	ATTR_ACCESS_R_W, 				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{9, "Termination ID base",	25,	ATTR_ACCESS_R_W,				ATTR_FORMAT_STRING,			ATTR_FULLY_SUPPORT,	 &mgcCfgDataDevIdFunc},
	{10, "Softswitch",			4, 	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT, 	ATTR_FULLY_SUPPORT,	 &generalAttrFunc},
	{11, "Message ID pointer",	2,	ATTR_ACCESS_R_W_SET_CREATE, 	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{255, "", 					0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_mgc_cfg_data_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_mgc_cfg_data_t omci_mgc_cfg_data_attr_data = {0};

omci_attr_t omci_mgc_cfg_data_attr ={
	(uint8_t *)&omci_mgc_cfg_data_attr_data,
	sizeof(omci_mgc_cfg_data_attr_data),
};

/*******************************************************************************************************************************
9.9.18 VoIP config data

********************************************************************************************************************************/
static attribute_func_t voipCfgDataAvaiProtoFunc = {
	getVOIPCfgDataAvaiProto,
	NULL
};
static attribute_func_t voipCfgDataProtoUsedFunc = {
	getVOIPCfgDataProtoUsed,
	setVOIPCfgDataProtoUsed
};
static attribute_func_t voipCfgDataAvaVoipCfgMethodsFunc = {
	getVOIPCfgDataAvaVoipCfgMethods,
	NULL
};
static attribute_func_t voipCfgDataMethodsUsedFunc = {
	NULL,
	setVOIPCfgDataMethodsUsed
};

static attribute_func_t voipCfgDatProVersionFunc = {
	getVOIPCfgDatProVersion,
	NULL
};

omci_attr_dscp_t omci_attr_voip_cfg_data_op[]={
	{0, "meId", 						2,	ATTR_ACCESS_R,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{1, "Available protocol", 		    1,	ATTR_ACCESS_R,		ATTR_FORMAT_BIT_FIELD,		ATTR_FULLY_SUPPORT, &voipCfgDataAvaiProtoFunc},
	{2, "protocol used",				1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &voipCfgDataProtoUsedFunc},
	{3, "Available voip cfg methods",   4,	ATTR_ACCESS_R,		ATTR_FORMAT_BIT_FIELD,		ATTR_FULLY_SUPPORT, &voipCfgDataAvaVoipCfgMethodsFunc},
	{4, "voip cfg methods used",		1,	ATTR_ACCESS_R_W,	ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &voipCfgDataMethodsUsedFunc},
	{5, "voip cfg addr pointer", 	    2,	ATTR_ACCESS_R_W,	ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{6, "voip cfg state",			    1,	ATTR_ACCESS_R,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{7, "retrieve profile", 			1,	ATTR_ACCESS_W,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{8, "profile version",	 		    25,	ATTR_ACCESS_R,		ATTR_FORMAT_STRING,			ATTR_FULLY_SUPPORT,	 &voipCfgDatProVersionFunc},
	{255, "", 							0,  0,                              0,                          0,                  NULL}
};

omci_me_func_t omci_me_voip_cfg_data_op ={
	NULL,
	NULL,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_voip_cfg_data_t omci_voip_cfg_data_attr_data = {0};

omci_attr_t omci_voip_cfg_data_attr ={
	(uint8_t *)&omci_voip_cfg_data_attr_data,
	sizeof(omci_voip_cfg_data_attr_data),
};


/*******************************************************************************************************************************
general function

********************************************************************************************************************************/


/*******************************************************************************************
**function name
	getEntryIdBySipUserData
**description:
	get sip entry id
 **retrun :
	-1: failure
	0:	success
**parameter:
	instId :	9.9.2 instance id
	entryId:	return entry id
********************************************************************************************/
int getEntryIdBySipUserData(uint16_t instId, uint16_t *entryId){
	omci_me_info_t me_info_buf={0};
	omci_sip_user_data_ptr sip_user_data_ptr=NULL;	

	if(entryId == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: entryId == NULL, fail\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	me_info_buf.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
	me_info_buf.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info_buf.attributes);	
	*entryId = (sip_user_data_ptr->pptpPtr & 0x00ff) -1;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success, instId=%d, entryId=%d\n",__FUNCTION__,__LINE__,instId,*entryId);
	return OMCI_VOIP_SUCC;
}
/*******************************************************************************************
**function name
	setSipDispName
**description:
	set display name by tcapi
 **retrun :
	-1: failure
	0:	success
**parameter:
	val :	value
	entryId:	entry id
********************************************************************************************/
int setSipDispName(char * val, uint16_t entryId){
	int ret = OMCI_VOIP_FAIL;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};

	if(val == NULL){
		goto end;
	}

	strncpy(tempBuffer,val,MAX_BUFFER_SIZE-1);
	if(omci_voip_set_sip_disp_name(tempBuffer, entryId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail !\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
end:
	return ret;

}
/*******************************************************************************************
**function name
	setSipUserPass
**description:
	set sip username and password by tcapi
 **retrun :
	-1: failure
	0:	success
**parameter:
	instId :	9.9.2 instance id
	entryId:	entry id
********************************************************************************************/
int setSipUserPass(uint16_t instId, uint16_t entryId){
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	char *userName = NULL;
	char *password = NULL;
	uint16_t authInstId = 0;
	omci_me_info_t me_info_buf={0};
	omci_sip_user_data_ptr sip_user_data_ptr=NULL;	
	omci_auth_security_method_ptr  auth_seu_method_ptr=NULL;

	me_info_buf.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
	me_info_buf.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info_buf.attributes);
	authInstId = sip_user_data_ptr->userNameOrPwd;

	me_info_buf.class_id = OMCI_CLASS_ID_AUTHENTICATION_METHOD;
	me_info_buf.inst_id = authInstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	auth_seu_method_ptr = (omci_auth_security_method_ptr)(me_info_buf.attributes);
	userName = auth_seu_method_ptr->username1;
	password = auth_seu_method_ptr->password;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_sip_user_name userName %s, password %s !\n",
		__FUNCTION__,__LINE__, userName, password);
	/*set sip auth user name */
	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	memcpy(tempBuffer,userName,OMCI_ME_MAX_STR_ATTR_LEN);

	if(omci_voip_set_sip_user_name(tempBuffer, entryId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_sip_user_name fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	/*set sip auth password*/	
	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	memcpy(tempBuffer,password,OMCI_ME_MAX_STR_ATTR_LEN);

	if(omci_voip_set_sip_password(tempBuffer, entryId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_sip_password fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success.\n",__FUNCTION__,__LINE__);
	return OMCI_VOIP_SUCC;

}
/*******************************************************************************************
**function name
	setSipURI
**description:
	set sip URI by tcapi
 **retrun :
	-1: failure
	0:	success
**parameter:
	instId :	9.9.2 instance id
	entryId:	entry id
********************************************************************************************/
int setSipURI(uint16_t instId, uint16_t entryId){
	uint16_t networkInstId = 0;
	uint16_t largeStrInstId = 0;
	uint8_t num = 0;
	uint16_t length = 0;
	uint8_t tmp_ptr[OMCI_ME_MAX_LARGE_STR_PART_NUM*OMCI_ME_MAX_STR_ATTR_LEN] = {0};
	omci_me_info_t me_info_buf={0};
	omci_sip_user_data_ptr sip_user_data_ptr=NULL;	
	omci_network_address_ptr network_address_ptr=NULL;
	omci_large_string_ptr large_string_ptr=NULL;

	/*get sip user data, attribute network instId*/
	me_info_buf.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
	me_info_buf.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info_buf.attributes);
	networkInstId = sip_user_data_ptr->voiceMailServerSipUri;

    if(networkInstId == 0xffff || networkInstId == 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: networkInstId is 0xFFFF.\n",__FILE__, __LINE__);
		return OMCI_VOIP_SUCC;
	}
	/*get address pointer  form 9.12.3 network address ME*/
	me_info_buf.class_id = OMCI_CLASS_ID_NETWORK_ADDRESS;
	me_info_buf.inst_id = networkInstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	network_address_ptr = (omci_network_address_ptr)(me_info_buf.attributes);
	largeStrInstId = network_address_ptr->addressPointer;

	/*get number of parts form 9.12.5 large string*/
	me_info_buf.class_id = OMCI_CLASS_ID_LARGE_STRING;
	me_info_buf.inst_id = largeStrInstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	large_string_ptr = (omci_large_string_ptr)(me_info_buf.attributes);
	num = large_string_ptr->numberOfParts;

	if(num > OMCI_ME_MAX_LARGE_STR_PART_NUM){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: number of part %d >15, fail\n",__FILE__, __LINE__, num);
		return OMCI_VOIP_FAIL;
	}

	length = num * OMCI_ME_MAX_STR_ATTR_LEN;
	memcpy(tmp_ptr, large_string_ptr->all_part.part, length);
	tmp_ptr[OMCI_ME_MAX_LARGE_STR_PART_NUM*OMCI_ME_MAX_STR_ATTR_LEN -1] = '\0';
	
	/*set sip URI*/	
	if(omci_voip_set_sip_uri((char *)tmp_ptr, entryId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]::omci_voip_set_sip_uri fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success, instId=%d, entryId=%d\n",__FUNCTION__,__LINE__,instId,entryId);
	return OMCI_VOIP_SUCC;

}
/*******************************************************************************************
**function name
	updateSipInfoByPPTP
**description:
	update 9.9.2 sip user date info
 **retrun :
	-1: failure
	0:	success
**parameter:
	instId :	9.9.2 instance id
	entryId:	entry id
********************************************************************************************/
int updateSipInfoByPPTP(uint16_t instId,uint16_t entryId){
	int ret = OMCI_VOIP_FAIL;
    uint16_t len = 0;
    char buff[LARGE_STRING_ME_MAX_LEN + 1] = {0};
    uint16_t  largeStringME_ID  = 0;
	uint8_t cfgMethod = 0;
	char  sipDisplayName[OMCI_SIP_DISP_NAME_ATTR_LEN+1]={0};
	omci_me_info_t me_info_buf={0};
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	omci_sip_user_data_ptr sip_user_data_ptr=NULL;
	int instCnt=0;
	uint16_t instList[32];
	int i=0;

	/* set pptp admin status, in case mismatch with driver */
	if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_PPTP_POTS_UNI,&instCnt) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}

	instCnt = instCnt > 32 ? 32 : instCnt;
	if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_PPTP_POTS_UNI,instList,instCnt) <= 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}

	for(i=0; i<instCnt; i++){
		me_info_buf.class_id = OMCI_CLASS_ID_PPTP_POTS_UNI;
		me_info_buf.inst_id = instList[i];
		if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
			return OMCI_VOIP_FAIL;
		}
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: set pots uni %d admin status\n",__FILE__, __LINE__,instList[i]);
		setPptpPotsUNIAdminStatus(&me_info_buf,omci_attr_pptp_pots_uni_op);
	}

	me_info_buf.class_id = OMCI_CLASS_ID_VOIP_CFG_DATA;
	me_info_buf.inst_id = 0;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info_buf.attributes);
	cfgMethod = voip_cfg_data_ptr->voipCfgMethodUsed;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: cfgMethod=%d\n",__FUNCTION__,__LINE__,cfgMethod);
	if(omci_voip_set_config_method_used(cfgMethod) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail!\n",__FUNCTION__,__LINE__);
	}


	/*set user part AOR*/
	me_info_buf.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
	me_info_buf.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info_buf.attributes);
	largeStringME_ID = sip_user_data_ptr->userPartAOR;
		 
    ret = omci_adpt_get_one_string_from_inst(OMCI_CLASS_ID_LARGE_STRING, largeStringME_ID ,buff, &len);
    if (( OMCI_VOIP_SUCC != ret ) || (0 == len) ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_adpt_get_one_string_from_inst fail.largeStringME_ID=%d\n",
			__FILE__, __LINE__,largeStringME_ID);
    }else{
    	ret = setSipUserPartAOR(buff, entryId);
        if(ret != OMCI_VOIP_SUCC){
    		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setSipDispName fail! ret=%d,entryId=%d\n",__FUNCTION__,__LINE__,ret,entryId);
    		return OMCI_VOIP_FAIL;
    	}
    }
        
	memcpy(sipDisplayName,sip_user_data_ptr->sipDisplayName,OMCI_SIP_DISP_NAME_ATTR_LEN);
	ret = setSipDispName(sipDisplayName, entryId);
	if( ret != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setSipDispName fail! ret=%d, entryId=%d\n",__FUNCTION__,__LINE__,ret, entryId);
		return OMCI_VOIP_FAIL;
	}

	ret = setSipAgentServersForSipUserData(instId , entryId);
    if( ret != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setSipAgentServersForSipUserData fail! ret=%d, entryId=%d\n",__FUNCTION__,__LINE__,ret, entryId);
		return OMCI_VOIP_FAIL;
	}

	ret = setVoIPSvcProfileForSipUserData(instId , entryId);
	if( ret != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setVoIPSvcProfileForSipUserData fail! ret=%d, entryId=%d\n",__FUNCTION__,__LINE__,ret, entryId);
		return OMCI_VOIP_FAIL;
	}
	
	ret = setSipUserPass(instId, entryId);
	if(ret != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setSipUserPass fail! ret=%d,entryId=%d\n",__FUNCTION__,__LINE__,ret,entryId);
		return OMCI_VOIP_FAIL;
	}

	ret = setSipURI(instId, entryId);
	if(ret != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setSipURI fail! entryId=%d\n",__FUNCTION__,__LINE__,entryId);
		return OMCI_VOIP_FAIL;
	}
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success, instId=%d, entryId=%d\n",__FUNCTION__,__LINE__,instId,entryId);
	return OMCI_VOIP_SUCC;
}

/*******************************************************************************************
**function name
	setMgcInfo
**description:
	set primary or secondary MGC infor by  9.9.16 MGC config data ME primary MGC or Secondary MGC attribute
 **retrun :
	-1: failure
	0:	success
**parameter:
	instId :	9.12.3 network address instance id
	flag :	0:primary, 1:secondary
********************************************************************************************/
static int setMgcInfo(uint16_t networkinstId, uint8_t flag){
	int ret = OMCI_VOIP_FAIL;
	uint16_t largeStrInstId = 0;
	uint8_t num = 0;
	uint8_t largeStrContentPtr[OMCI_ME_MAX_LARGE_STR_PART_NUM*OMCI_ME_MAX_STR_ATTR_LEN] = {0};
	uint16_t length=0;
	omci_me_info_t me_info_buf={0};
	omci_network_address_ptr network_address_ptr=NULL;	
	omci_large_string_ptr large_string_ptr=NULL;

	switch(flag){
		case OMCI_H248_PRIMARY_ATTR_INDEX:
		case OMCI_H248_SECNDARY_ATTR_INDEX:
			break;
		default:
			goto end;
	}

	/*get address pointer  form 9.12.3 network address ME*/	
	me_info_buf.class_id = OMCI_CLASS_ID_NETWORK_ADDRESS;
	me_info_buf.inst_id = networkinstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		goto end;
	}
	network_address_ptr = (omci_network_address_ptr)(me_info_buf.attributes);
	largeStrInstId = network_address_ptr->addressPointer;

	/*get number of parts form 9.12.5 large string*/
	me_info_buf.class_id = OMCI_CLASS_ID_LARGE_STRING;
	me_info_buf.inst_id = largeStrInstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		goto end;
	}
	large_string_ptr = (omci_large_string_ptr)(me_info_buf.attributes);
	num = large_string_ptr->numberOfParts;

	if(num > OMCI_ME_MAX_LARGE_STR_PART_NUM){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: number of part %d >15, fail",__FUNCTION__,__LINE__,num);
		goto end;
	}

	length = num * OMCI_ME_MAX_STR_ATTR_LEN;
	memcpy(largeStrContentPtr, large_string_ptr->all_part.part, length);
	largeStrContentPtr[OMCI_ME_MAX_LARGE_STR_PART_NUM*OMCI_ME_MAX_STR_ATTR_LEN -1] = '\0';

	if(omci_voip_set_mgc_info((char *)largeStrContentPtr, flag) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_set_mgc_info fail !\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d.\n",__FUNCTION__,__LINE__,ret);
	return ret;

}


/*******************************************************************************************************************************
9.9.1 Physical path termination point POTS UNI

********************************************************************************************************************************/
#define classMask   0x30
#define modeMask    0x80
#define potsIdMask  0xff
int pptp_pots_uni_test_support(omci_me_info_ptr me_info)
{
	int ret = OMCI_CMD_SUCCESS;
	uint8_t testType = 0;
    uint8_t potsId = 0;
	omci_voip_dev_status_t dev_status = 0;
		
	if(me_info == NULL)
		return OMCI_CMD_ERROR;
	
	testType = me_info->attributes[0];
	if(0 == (testType & 0x30 )>>4)	 /*Test class 0*/
	{
		if(0 == (testType & 0x80)>>4)	/*normal mode*/
		{
			potsId = ((me_info->inst_id)&(potsIdMask))-1;
			if(0 != omci_voip_get_device_status(&dev_status, potsId)){
				return OMCI_CMD_ERROR;
			}

			if(dev_status == VOIP_DEVICE_BUSY){
				return OMCI_DEVICE_BUSY;
			}
		}
	}
	else if(1 == (testType & 0x30)>>4)  /*Test class 1*/
	{
		/*reserve for class 1 operation*/
	}
	else{
		ret = OMCI_CMD_NOT_SUPPORT;
	}
	return ret;

}

int setPptpPotsUNIARCValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint8_t arcValue = 0;
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;
	evt_arc_data_t arc_data = {0};

	if(me_info == NULL ||	me_info->attributes == NULL  || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return -1;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);

	arc_data.class_id = me_info->class_id;
	arc_data.inst_id = me_info->inst_id;
	arc_data.interval = pptp_pots_uni_ptr->arcInterval;

	arcValue = pptp_pots_uni_ptr->arc;
	if(arcValue == ARC_ENABLE){
		arc_data.arc_en = ARC_ENABLE;
		omci_adpt_report_event(OMCI_EVENT_ARC, &arc_data);
	}else if(arcValue == ARC_DISABLE){
		arc_data.arc_en = ARC_DISABLE;
		omci_adpt_report_event(OMCI_EVENT_ARC, &arc_data);
	}else{
		return -1;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return 0, arcValue=%d\n",__FUNCTION__,__LINE__,arcValue);	
	return 0;
}

int getPptpPotsUNIAdminStatus(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;
	uint8_t state = OMCI_PPTP_UNI_STATE_LOCK;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes	== NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	omci_voip_get_admin_state(tempBuffer,MAX_BUFFER_SIZE);
	if(strcmp(tempBuffer,"Yes") == 0){
		state = OMCI_PPTP_UNI_STATE_UNLOCK;
	}else if(strcmp(tempBuffer,"No") == 0){
		state = OMCI_PPTP_UNI_STATE_LOCK;
	}else{
		goto end;
	}
	
	pptp_pots_uni_ptr->adminState = state;
	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, adminState=%d\n",__FUNCTION__,__LINE__,ret,pptp_pots_uni_ptr->adminState);	
	return ret;

}

int setPptpPotsUNIAdminStatus(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint8_t state = OMCI_PPTP_UNI_STATE_LOCK;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes	== NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	state = pptp_pots_uni_ptr->adminState;
	if(state == OMCI_PPTP_UNI_STATE_UNLOCK){
		strcpy(tempBuffer, "Yes");
	}else if(state == OMCI_PPTP_UNI_STATE_LOCK){
		strcpy(tempBuffer, "No");
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: ERROR! state=%d\n",__FUNCTION__,__LINE__,state);
		return OMCI_VOIP_FAIL;
	}

	if(omci_voip_set_admin_state(tempBuffer, (me_info->inst_id & 0xFF)-1 ) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_admin_state fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}	

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, adminState=%d\n",__FUNCTION__,__LINE__,pptp_pots_uni_ptr->adminState);	
	return OMCI_VOIP_SUCC;
}

int getPptpPotsUNIRxGain(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint16_t instance = 0;
	char buf[MAX_BUFFER_SIZE] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	instanceId = pptp_pots_uni_ptr->meId;
	if(isFiberhome_551601){
		instance = instanceId - 1;
	}else{
		instance = (instanceId & 0xFF) -1;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]:instanceId=%d, instance=%d\r\n", __FUNCTION__,__LINE__,instanceId, instance);
	if(0 != omci_voip_get_rx_gain(buf,MAX_BUFFER_SIZE,instance)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_get_rx_gain fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	pptp_pots_uni_ptr->rxGain = atoi(buf);

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, rxGain=%d\n",__FUNCTION__,__LINE__,pptp_pots_uni_ptr->rxGain);	
	return OMCI_VOIP_SUCC;
}

int setPptpPotsUNIRxGain(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint16_t instance = 0;
	char valueBuf[4] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	instanceId = pptp_pots_uni_ptr->meId;
	if(isFiberhome_551601){
		instance = instanceId - 1;
	}
	else{
		instance = (instanceId & 0xFF) -1;
	}
	
	sprintf(valueBuf, "%d", pptp_pots_uni_ptr->rxGain);
	if(0 != omci_voip_set_rx_gain(valueBuf,instance)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_rx_gain fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, rxGain=%d\n",__FUNCTION__,__LINE__,pptp_pots_uni_ptr->rxGain);	
	return OMCI_VOIP_SUCC;
}

int getPptpPotsUNITxGain(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint16_t instance = 0;
	char buf[MAX_BUFFER_SIZE] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	instanceId = pptp_pots_uni_ptr->meId;
	if(isFiberhome_551601){
		instance = instanceId - 1;
	} else{
		instance = (instanceId & 0xFF) -1;
	}
	
	if(0 != omci_voip_get_tx_gain(buf,MAX_BUFFER_SIZE,instance)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_get_tx_gain fail !\n",__FUNCTION__,__LINE__);
		return -1;
	}

	pptp_pots_uni_ptr->txGain = atoi(buf);
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, txGain=%d\n",__FUNCTION__,__LINE__,pptp_pots_uni_ptr->txGain);	
	return OMCI_VOIP_SUCC;

}
int setPptpPotsUNITxGain(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint16_t instance = 0;
	char valueBuf[4] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes == NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	instanceId = pptp_pots_uni_ptr->meId;
	if(isFiberhome_551601){
		instance = instanceId - 1;
	} else{
		instance = (instanceId & 0xFF) -1;
	}

	sprintf(valueBuf, "%d", pptp_pots_uni_ptr->txGain);
	if(0 != omci_voip_set_tx_gain(valueBuf,instance)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_tx_gain fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, txGain=%d\n",__FUNCTION__,__LINE__,pptp_pots_uni_ptr->txGain);	
	return OMCI_VOIP_SUCC;
}
int getPptpPotsUNIHookState(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint16_t instance = 0;
	char buf[10] = {0};
	omci_pptp_pots_uni_ptr pptp_pots_uni_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	pptp_pots_uni_ptr = (omci_pptp_pots_uni_ptr)(me_info->attributes);
	instanceId = pptp_pots_uni_ptr->meId;
	if(isFiberhome_551601){
		instance = instanceId - 1;
	} else{
		instance = (instanceId & 0xFF) -1;
	}
	
	if(0 != omci_voip_get_hook_state(buf,10,instance)){
		strncpy(buf, "0", 2);
	}else{
        if(NULL != strstr(buf,"Off"))
    		strncpy(buf, "1", 2);
    	else
    		strncpy(buf, "0", 2);
    }

	pptp_pots_uni_ptr->hookState = (uint8_t)atoi(buf);
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, hookState=%d\n",__FUNCTION__,__LINE__,pptp_pots_uni_ptr->hookState);	
	return OMCI_VOIP_SUCC;
}

static int PPTP_POTS_UNITestRst_HIGH_VOLTAGE(omci_me_info_ptr me_info, uint8_t slicVendor)
{
    uint8_t *tmp = NULL;
    int data[8] = {0};
    FILE * stream;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}
    tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_DC_FLAGS;
    *tmp = (*tmp)|(0x3f);
    tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_AC_FLAGS;
    *tmp = (*tmp)|(0x3f);                       
    
    system("echo 0 1 >/proc/fxs/sliclinetest");
    stream = fopen("/proc/fxs/sliclinetest", "r");
    if(NULL == stream){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]fopen /proc/fxs/sliclinetest fail.\n",__FUNCTION__,__LINE__);
		return -1;
	}
    /*ACTip ACRing DCTip DCRing*/
    if(0 != fscanf(stream, "%d %d %d %d", &data[0], &data[1], &data[2], &data[3])){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]fscanf stream fail.\n",__FUNCTION__,__LINE__);
		fclose(stream);
		return -1;
	}
		
    fclose(stream);

    tmp = (uint8_t *)(me_info->attributes)+OFS_TG_DC;
    put16(tmp, ((data[2]/1000)==0)?1:(data[2]/1000));
    tmp = (uint8_t *)(me_info->attributes)+OFS_RG_DC;
    put16(tmp, ((data[3]/1000)==0)?1:(data[3]/1000));

    if((data[2]>40000)){
        tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_DC_FLAGS;
        *tmp = (*tmp)&(0x1f);
    }
    if((data[3]>40000)){
        tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_DC_FLAGS;
        *tmp = (*tmp)&(0x3b);
    }
    
    if(Zarlink == slicVendor)
    {
        tmp = (uint8_t *)(me_info->attributes)+OFS_TG_AC;
        *tmp = ((data[0]/1000)==0)?1:(data[0]/1000);
        tmp = (uint8_t *)(me_info->attributes)+OFS_RG_AC;
        *tmp = ((data[1]/1000)==0)?1:(data[1]/1000);
        if(data[0]>50000){
            tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_AC_FLAGS;
            *tmp = (*tmp)&(0x1f);
        }
        if(data[1]>50000){
            tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_AC_FLAGS;
            *tmp = (*tmp)&(0x3b);
        }
    }
    else
    {
        tmp = (uint8_t *)(me_info->attributes)+OFS_TG_AC;
        *tmp = ((sqrt(data[0])*100/1000)==0)?1:(sqrt(data[0])*100/1000);
        tmp = (uint8_t *)(me_info->attributes)+OFS_RG_AC;
        *tmp = ((sqrt(data[1])*100/1000)==0)?1:(sqrt(data[1])*100/1000);
        if(sqrt(data[0])*100>50000){
            tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_AC_FLAGS;
            *tmp = (*tmp)&(0x1f);
        }
        if(sqrt(data[1])*100>50000){
            tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_AC_FLAGS;
            *tmp = (*tmp)&(0x3b);
        }
    }
	return 0;
}

static int PPTP_POTS_UNITestRst_EMF(omci_me_info_ptr me_info, uint8_t slicVendor)
{
	return 0;
}

static int PPTP_POTS_UNITestRst_RESISTANCE(omci_me_info_ptr me_info, uint8_t slicVendor)
{
    uint8_t *tmp = NULL;
    int data[8] = {0};
    FILE * stream;
    
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}
    tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_R_FLAGS_1;
    *tmp = (*tmp)|(0x3f);
    tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_R_FLAGS_2;
    *tmp = (*tmp)|(0x38);

    if(Zarlink == slicVendor)
    {
       system("echo 0 4 >/proc/fxs/sliclinetest");
       stream = fopen("/proc/fxs/sliclinetest", "r");
    }
    else
    {
       system("echo 0 3 >/proc/fxs/sliclinetest");
       stream = fopen("/proc/fxs/sliclinetest", "r");
    }
    if(NULL == stream){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]fopen fail.\n",__FUNCTION__,__LINE__);
		return -1;
	}
    /*TIP_RESISTANCE RING_RESISTANCE TIP_RING_RESISTANCE*/
    if(0 != fscanf(stream, "%d %d %d", &data[0], &data[1], &data[2])){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]fscanf stream fail.\n",__FUNCTION__,__LINE__);
		fclose(stream);
		return -1;
	}
    fclose(stream);

    tmp = (uint8_t *)(me_info->attributes)+OFS_TG_DC_R;
    put16(tmp, (data[0]/10/1000)<0xffff?(data[0]/10/1000):0xffff);
    tmp = (uint8_t *)(me_info->attributes)+OFS_RG_DC_R;
    put16(tmp, (data[0]/10/1000)<0xffff?(data[0]/10/1000):0xffff);
    tmp = (uint8_t *)(me_info->attributes)+OFS_TR_DC_R;
    put16(tmp, (data[0]/10/1000)<0xffff?(data[0]/10/1000):0xffff);

    if(data[0]/10<20000){
       tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_R_FLAGS_1;
       *tmp = (*tmp)|(0x1f);
    }
    if(data[1]/10<20000){
       tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_R_FLAGS_1;
       *tmp = (*tmp)|(0x3b);
    }
    if(data[2]/10<20000){
       tmp = (uint8_t *)(me_info->attributes)+OFS_LOOP_R_FLAGS_2;
       *tmp = (*tmp)|(0x1f);
    }   
	return 0;
}

static int PPTP_POTS_UNITestRst_OFF_HOOK(omci_me_info_ptr me_info, uint8_t slicVendor)
{
	return 0;
}

static int PPTP_POTS_UNITestRst_RINGER(omci_me_info_ptr me_info, uint8_t slicVendor)
{
	return 0;
}

static int PPTP_POTS_UNITestRst_SELF_TEST(omci_me_info_ptr me_info, uint8_t slicVendor)
{
    uint8_t *tmp = NULL;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}
    tmp = (uint8_t *)(me_info->attributes)+OFS_SELF_VEND_TEST;
    *tmp = 0x02;
	return 0;
}

static int PPTP_POTS_UNITestRst_DIAL_TONE(omci_me_info_ptr me_info, uint8_t slicVendor)
{
	return 0;
}

static int omciPPTP_POTS_UNITestRstClass0(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    uint8_t *tmp = NULL;
    char data[8] = {0};
    uint8_t mask = 0;
    uint8_t slicVendor = 0;
    FILE * stream;
    
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

	mask = (me_info->attributes[0]) & (0x0f);

    stream = fopen("/proc/fxs/slicType", "r");
    if(NULL == stream){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]fopen /proc/fxs/slicType fail.\n",__FUNCTION__,__LINE__);
		return -1;
	}
    if(0 != fscanf(stream, "%c %c", &data[0], &data[1])){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]fscanf stream fail.\n",__FUNCTION__,__LINE__);
		fclose(stream);
		return -1;
	}
    fclose(stream);

    if(('s'==data[0])&&('i'==data[1])){
        slicVendor = Silicon;
    }
    else{
        slicVendor = Zarlink;
    }

    tmp = (uint8_t *)(me_info->attributes)+OFS_MLT_RESULT;
    *tmp = 0x3f;
    
    if((ALL_MLT == mask)||(HIGH_VOLTAGE == mask)){
        PPTP_POTS_UNITestRst_HIGH_VOLTAGE(me_info, slicVendor);
    }
    
    if((ALL_MLT == mask)||(EMF == mask)){           
        /*reserve for EMF test*/
        PPTP_POTS_UNITestRst_EMF(me_info, slicVendor);
    }
    
    if((ALL_MLT == mask)||(RESISTANCE == mask)){
       PPTP_POTS_UNITestRst_RESISTANCE(me_info, slicVendor);
    }
    
    if((ALL_MLT == mask)||(OFF_HOOK == mask)){        
        /*reserve for OFF_HOOK test*/
        PPTP_POTS_UNITestRst_OFF_HOOK(me_info, slicVendor);
    }
    
    if((ALL_MLT == mask)||(RINGER == mask)){           
        /*reserve for TINGER test*/
        PPTP_POTS_UNITestRst_RINGER(me_info, slicVendor);
    }
    
    if((ALL_MLT == mask)||(SELF_TEST == mask)){       
        /*reserve for SELF_TEST test*/
        PPTP_POTS_UNITestRst_SELF_TEST(me_info, slicVendor);
    }
    
    if((ALL_MLT == mask)||(DIAL_TONE == mask)){
        /*reserve for DIAL_TONE test*/
        PPTP_POTS_UNITestRst_DIAL_TONE(me_info, slicVendor);
    }

    return 0;
}
static int omciPPTP_POTS_UNITestRstClass1(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

    return 0;
}
static int omciPPTP_POTS_UNITestRstMsgHandleBaseline(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

	if(0==((0x30&(me_info->attributes[0])) >> 4))/*class 0*/
	{
		omciPPTP_POTS_UNITestRstClass0(me_entry, me_info);
	}
	else if(1==((0x30&(me_info->attributes[0])) >> 4))/*class 1*/
	{
		/*reserve for class 1 operation*/
		omciPPTP_POTS_UNITestRstClass1(me_entry, me_info);
	}
	else
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"testType error!");
		return -1;
	}

	omci_adpt_report_event(OMCI_EVENT_TEST_RESULT,me_info);
	
	return 0;
}

static int omciPPTP_POTS_UNITestRstMsgHandleExtended(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	uint8_t *tmp = NULL;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

	if((me_info->attributes[0] == 0x07) ||((me_info->attributes[0] & 0x08) != 0) )/* test*/
	{
	/*send test result packets*/
		/*PPTP_POTS UNI  test MLT drop test result	14*/
		tmp = (uint8_t *)(me_info->attributes);
		memset(tmp,0,me_info->attr_len);
		*tmp = 1;
		
		/*PPTP_POTS UNI  test MLT result of test	15*/
		tmp = tmp + 1;
		*tmp = 1;
		/*PPTP_POTS UNI  test dial tone make-break flags  16*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test dial tone power flags  17*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test loop test DC voltage flags  18*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test loop test AC voltage flags  19*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test loop test resistance flags 1	20*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test loop test resistance flags 2	21*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test Time to draw dial tone 22*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test Time to break dial tone 23*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test total dial tone power pwasurement 24*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test quiet channel power measurement 25*/
		tmp = tmp + 1;
		*tmp = 0;
		
		/*PPTP_POTS UNI  test Tip-ground DC voltage 26-27*/
		tmp = tmp + 1;
		put16(tmp, 0);
	
		/*PPTP_POTS UNI  test Ring-ground DC volatage 28-29*/
		tmp = tmp + 2;
		put16(tmp, 0);
	
		/*PPTP_POTS UNI  test Tip-ground AC voltage 30*/
		tmp = tmp + 2;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test Ring-ground DC volatage 31*/
		tmp = tmp + 1;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test Tip-ground DC resistance 32-33*/
		tmp = tmp + 1;
		put16(tmp, 0);
	
		/*PPTP_POTS UNI  test Ring-ground DC resistance 34-35*/
		tmp = tmp + 2;
		put16(tmp, 0);
	
		/*PPTP_POTS UNI  test Tip-ring	DC resistance 36-37*/
		tmp = tmp + 2;
		put16(tmp, 0);
	
		/*PPTP_POTS UNI  test Ringer equivalence 38*/
		tmp = tmp + 2;
		*tmp = 0;
	
		/*PPTP_POTS UNI  test Pointer to a general purpose buffer 39-40*/
		tmp = tmp + 1;
		put16(tmp, 0);
		
		me_info->attr_len = 27;
		omci_adpt_report_event(OMCI_EVENT_TEST_RESULT,me_info);
	}		
	else
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"[%s][%d] testType error!\n",__FUNCTION__,__LINE__);
		return -1;
	}

	return 0;
}


int omci_me_pptp_pots_uni_test_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	int ret = 0;
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)||(NULL == me_info->attributes)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}
	if(me_info->dev_id == OMCI_BASELINE_MSG)
	{
		ret = omciPPTP_POTS_UNITestRstMsgHandleBaseline(me_entry, me_info);
		if (ret != 0)
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "startTest:omciPPTP_POTS_UNITestRstMsgHandleBaseline fail\n");	
	}			
	else if(me_info->dev_id == OMCI_EXTENED_MSG)
	{
		ret = omciPPTP_POTS_UNITestRstMsgHandleExtended(me_entry, me_info);
		if (ret != 0)
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "startTest:omciPPTP_POTS_UNITestRstMsgHandleExtended fail\n");				
	}
	else
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "startTest:----message format is invalid!\n");
	}

	return 0;
}

/*******************************************************************************************
**function name
	setSipUserPartAOR
**description:
	set user part AOR by tcapi
 **retrun :
	-1: failure
	0:	success
**parameter:
	val :	value
	entryId:	entry id
********************************************************************************************/
int setSipUserPartAOR(char * val, uint16_t entryId){
	int ret = OMCI_VOIP_FAIL;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};

	if(val == NULL){
		goto end;
	}

	strncpy(tempBuffer,val,MAX_BUFFER_SIZE-1);
	if(omci_voip_set_user_part_aor(tempBuffer, entryId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s]:omci_voip_set_user_part_aor fail ![%d]\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
end:
	return ret;

}

int setSipUserDataUserPartAOR(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;	
	uint16_t instId = 0;
	uint16_t largeStrInstId=0;
	uint16_t entryId = 0;
	char buff[LARGE_STRING_ME_MAX_LEN + 1] = {0};
	uint16_t len=0;
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);
	largeStrInstId = sip_user_data_ptr->userPartAOR;

	if(me_info->msg_type== MT_OMCI_MSG_TYPE_CREAT){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] set_by_create, return success!\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_SUCC;
	}

	ret = omci_adpt_get_one_string_from_inst(OMCI_CLASS_ID_LARGE_STRING, largeStrInstId ,buff, &len);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] get large string [%s]\n",__FUNCTION__,__LINE__,buff);
	if ( OMCI_VOIP_SUCC != ret  || len > LARGE_STRING_ME_MAX_LEN)
		return ret;

	/*get instance id*/
	instId = sip_user_data_ptr->meId;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] instId [%d]\n",__FUNCTION__,__LINE__,instId);

	/*get entry id*/
	if(getEntryIdBySipUserData(instId, &entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR,"[%s][%d]:getEntryIdBySipUserData, fail!\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"[%s][%d] entryId [%d]\n",__FUNCTION__,__LINE__,entryId);
	
	if(setSipUserPartAOR(buff, entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:setSipDispName fail!\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, userPartAOR=%d\n",__FUNCTION__,__LINE__,sip_user_data_ptr->userPartAOR);	
	return OMCI_VOIP_SUCC;
}
int getSipUserDataDispName(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t entryId = 0;
	uint16_t instId = 0;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);

	/*get instance id*/
	instId = sip_user_data_ptr->meId;

	/*get entry id*/
	if(getEntryIdBySipUserData(instId, &entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: getEntryIdBySipUserData, fail",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	omci_voip_get_sip_disp_name(tempBuffer, MAX_BUFFER_SIZE,entryId);
	if(strlen(tempBuffer) > OMCI_MAX_SIP_DISP_NAME_LEN){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: tempBuffer exceding!",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	memcpy(sip_user_data_ptr->sipDisplayName, tempBuffer, OMCI_SIP_DISP_NAME_ATTR_LEN);

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC, sipDisplayName=%s\n",__FUNCTION__,__LINE__,tempBuffer);	
	return OMCI_VOIP_SUCC;

}
int setSipUserDataDispName(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instId = 0;
	uint16_t entryId = 0;
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);

	if(me_info->msg_type== MT_OMCI_MSG_TYPE_CREAT){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] set_by_create, return success!\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_SUCC;
	}

	/*get instance id*/
	instId = sip_user_data_ptr->meId;

	/*get entry id*/
	if(getEntryIdBySipUserData(instId, &entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: getEntryIdBySipUserData, fail\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	if(setSipDispName(sip_user_data_ptr->sipDisplayName, entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:setSipDispName fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC.\n",__FUNCTION__,__LINE__);	
	return OMCI_VOIP_SUCC;

}

int setSipUserDataUserPass(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instId = 0;
	uint16_t entryId = 0;
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);
	
	if(me_info->msg_type== MT_OMCI_MSG_TYPE_CREAT){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] set_by_create, return success!\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_SUCC;
	}

	/*get instance id*/
	instId = sip_user_data_ptr->meId;

	/*get entry id*/
	if(getEntryIdBySipUserData(instId, &entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: getEntryIdBySipUserData, fail\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	if(setSipUserPass(instId, entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setSipUserPass fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	/* LTM */
	omci_voip_set_sip_enable("Yes", entryId);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "LTM: set VoIPBasic_Entry %d SIPEnable to Yes", entryId);

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC.\n",__FUNCTION__,__LINE__);	
	return OMCI_VOIP_SUCC;
}

int setSipUserDataSipURI(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instId = 0;
	uint16_t entryId = 0;
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);
	
	if(me_info->msg_type== MT_OMCI_MSG_TYPE_CREAT){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] set_by_create, return success!\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_SUCC;
	}

	/*get instance id*/
	instId = sip_user_data_ptr->meId;

	/*get entry id*/
	if(getEntryIdBySipUserData(instId, &entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: getEntryIdBySipUserData, fail\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	if(setSipURI(instId, entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]::setSipURI fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC.\n",__FUNCTION__,__LINE__);	
	return OMCI_VOIP_SUCC;

}
int getSipUserDataExpTime(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint32_t expTime = 0;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);

	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	omci_voip_get_voice_exp_time(tempBuffer, MAX_BUFFER_SIZE);

	expTime = atoi(tempBuffer);
	sip_user_data_ptr->voiceMailSubsExpTime = expTime;
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC. expTime=%u\n",__FUNCTION__,__LINE__,expTime);	
	return OMCI_VOIP_SUCC;

}
int setSipUserDataExpTime(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);

	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	sprintf(tempBuffer,"%d",sip_user_data_ptr->voiceMailSubsExpTime);
	if(omci_voip_set_voice_exp_time(tempBuffer) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s]:omci_voip_set_voice_exp_time fail ![%d]\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC. \n",__FUNCTION__,__LINE__);	
	return OMCI_VOIP_SUCC;

}
int setSipUserDataPPTPPointer(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t oldPPTPMeId = 0;
	uint16_t newPPTPMeId = 0;
	uint16_t instId = 0;
	uint16_t entryId = 0;
	uint8_t changeEntryFlag = OMCI_VOIP_NO_CHANGE_ENTRY;
	omci_sip_user_data_ptr sip_user_data_ptr = NULL;
	omci_sip_user_data_ptr old_sip_user_data_ptr=NULL;
	omci_me_info_t me_info_buf={0};

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info->attributes);
	newPPTPMeId = sip_user_data_ptr->pptpPtr;

	/*get instance id*/
	instId = sip_user_data_ptr->meId;
		
	if(me_info->msg_type == MT_OMCI_MSG_TYPE_CREAT){
		changeEntryFlag = OMCI_VOIP_CHANGE_ENTRY;
	}else{			
		me_info_buf.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
		me_info_buf.inst_id = instId;
		if(omci_attr_get_old_data_except_table_attr(&me_info_buf) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
			return OMCI_VOIP_FAIL;
		}
		old_sip_user_data_ptr = (omci_sip_user_data_ptr)(me_info_buf.attributes);
		oldPPTPMeId = old_sip_user_data_ptr->pptpPtr;
		if(newPPTPMeId != oldPPTPMeId){
			changeEntryFlag = OMCI_VOIP_CHANGE_ENTRY;
		}
	}

	/*When create instance or create PPTP instace id, update attribute value to system*/
	if(changeEntryFlag == OMCI_VOIP_CHANGE_ENTRY){
		entryId = (newPPTPMeId & 0x00FF)-1;
		
		if(updateSipInfoByPPTP(instId, entryId) != OMCI_VOIP_SUCC){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: updateSipInfoByPPTP, fail\n",__FUNCTION__,__LINE__);
			return OMCI_VOIP_FAIL;
		}
	}	
	
	uint16_t port_id = newPPTPMeId & 0x00FF;

	omci_voip_set_sip_port_id(port_id, instId);

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return OMCI_VOIP_SUCC. newPPTPMeId=%d\n",__FUNCTION__,__LINE__,newPPTPMeId);	
	return OMCI_VOIP_SUCC;

}

int omci_me_sip_user_data_del_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	uint16_t entryId = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: Enter\n",__FUNCTION__,__LINE__);

	if((NULL == me_entry)||(NULL == me_info)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

	if(getEntryIdBySipUserData(me_info->inst_id, &entryId) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: getEntryIdBySipUserData, fail\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	if(omci_voip_reset_sip_user_entry(entryId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s]:omci_voip_reset_sip_user_entry fail ![%d]\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	return OMCI_VOIP_SUCC;
}

int omci_me_sip_user_data_create_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: Enter\n",__FUNCTION__,__LINE__);

	omci_me_general_create_op(me_entry, me_info);

	omci_set_voip_basic_user();

	return OMCI_VOIP_SUCC;
}

int setSipAgentCfgDataHostPartUri(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;
	uint16_t len=0;
	uint16_t largeStrInstId=0;
    char buff[LARGE_STRING_ME_MAX_LEN + 1] = {0};
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	
	largeStrInstId = sip_agent_cfg_ptr->hostPartUri;    
	ret = omci_adpt_get_one_string_from_inst(OMCI_CLASS_ID_LARGE_STRING, largeStrInstId ,buff, &len);
    if ( OMCI_VOIP_SUCC != ret){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_adpt_get_one_string_from_inst fail, ret=%d. \n",__FUNCTION__,__LINE__,ret);	
        return ret;
    }

	omci_voip_set_host_domain(buff);
	return ret;
}

int setSipAgentCfgDataProxyAddr(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;
	uint16_t len=0;
	uint16_t largeStrInstId=0;
    char buff[LARGE_STRING_ME_MAX_LEN + 1] = {0};
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	

    /* If outbound SIP proxy is not used, should set to null */
    if (0 == sip_agent_cfg_ptr->proxySrvAddrPtr){
        return OMCI_VOIP_SUCC;
    }

	/* LTM */
	omci_voip_set_proxy_enable("Yes");

	largeStrInstId = sip_agent_cfg_ptr->proxySrvAddrPtr;    
	ret = omci_adpt_get_one_string_from_inst(OMCI_CLASS_ID_LARGE_STRING, largeStrInstId ,buff, &len);
    if ( OMCI_VOIP_SUCC != ret){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_adpt_get_one_string_from_inst fail, ret=%d. \n",__FUNCTION__,__LINE__,ret);	
        return ret;
    }

	ret = omci_voip_set_proxy_server_addr(buff);
    if ( OMCI_VOIP_SUCC != ret){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_set_proxy_server_addr fail, ret=%d. \n",__FUNCTION__,__LINE__,ret);	
        return ret;
    }

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success!  proxy server addr %s \n",__FUNCTION__,__LINE__, buff);
    return OMCI_VOIP_SUCC;
}


int setSipAgentCfgDataOutBoundProxyAddr(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;
	uint16_t len=0;
	uint16_t largeStrInstId=0;
    char buff[LARGE_STRING_ME_MAX_LEN + 1] = {0};
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	

    /* If outbound SIP proxy is not used, should set to null */
    if (0 == sip_agent_cfg_ptr->outbndProxyAddrPtr){
        return OMCI_VOIP_SUCC;
    }

	largeStrInstId = sip_agent_cfg_ptr->outbndProxyAddrPtr;    
	ret = omci_adpt_get_one_string_from_inst(OMCI_CLASS_ID_LARGE_STRING, largeStrInstId ,buff, &len);
    if ( OMCI_VOIP_SUCC != ret){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_adpt_get_one_string_from_inst fail, ret=%d. \n",__FUNCTION__,__LINE__,ret);	
        return ret;
    }

	ret = omci_voip_set_out_proxy_addr(buff);
    if ( OMCI_VOIP_SUCC != ret){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_set_out_proxy_addr fail, ret=%d. \n",__FUNCTION__,__LINE__,ret);	
        return ret;
    }

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success!\n",__FUNCTION__,__LINE__);
    return OMCI_VOIP_SUCC;
}


int setSipAgentCfgDataSIPRegistrar(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;
	uint16_t len=0;
	uint16_t largeStrInstId=0;
	uint16_t networkAddressInstId=0;
    char buff[LARGE_STRING_ME_MAX_LEN + 1] = {0};
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;
	omci_network_address_ptr network_address_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	
	networkAddressInstId = sip_agent_cfg_ptr->sipRegistrar;

	omci_me_info_t me_info_buf={0};

	me_info_buf.class_id = OMCI_CLASS_ID_NETWORK_ADDRESS;
	me_info_buf.inst_id = sip_agent_cfg_ptr->sipRegistrar;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return -1;
	}

	network_address_ptr = (omci_network_address_ptr)(me_info_buf.attributes);
	largeStrInstId = network_address_ptr->addressPointer;

	ret = omci_adpt_get_one_string_from_inst(OMCI_CLASS_ID_LARGE_STRING, largeStrInstId ,buff, &len);
    if ( OMCI_VOIP_SUCC != ret){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_adpt_get_one_string_from_inst fail, ret=%d. \n",__FUNCTION__,__LINE__,ret);	
        return OMCI_VOIP_SUCC;
    }

	omci_voip_set_sip_reg(buff);

	return OMCI_VOIP_SUCC;
}

 
int getSipAgentCfgDataSipRegExpTime(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
    char buf[20];
	uint32_t regExpireTime;
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	

    if (0 != omci_voip_get_reg_exp_time(buf, sizeof(buf))){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_get_reg_exp_time fail! \n",__FUNCTION__,__LINE__);
        return OMCI_VOIP_FAIL;
    }

    regExpireTime = strtol(buf, NULL, 10);

    if ( 0 == regExpireTime && ( EINVAL == errno || ERANGE == errno) ){
        return OMCI_VOIP_FAIL;
    }

	sip_agent_cfg_ptr->sipRegExpTime = regExpireTime;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! regExpireTime=%d\n",__FUNCTION__,__LINE__,regExpireTime);
    return OMCI_VOIP_SUCC;

}
int setSipAgentCfgDataSipRegExpTime(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
    char buf[20];
	uint32_t regExpireTime;
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	
	regExpireTime = sip_agent_cfg_ptr->sipRegExpTime;

    snprintf(buf, 20, "%u", regExpireTime);

    if( 0 != omci_voip_set_reg_exp_time(buf) ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_set_reg_exp_time fail! \n",__FUNCTION__,__LINE__);
        return OMCI_VOIP_FAIL;
    }

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! regExpireTime=%d\n",__FUNCTION__,__LINE__,regExpireTime);
    return OMCI_VOIP_SUCC;
}

int getSipAgentCfgDataSIPReregTime(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
    char buf[20];
	uint32_t retryInterval;
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	

    if (0 != omci_voip_get_re_reg_time(buf, sizeof(buf))){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_get_re_reg_time fail! \n",__FUNCTION__,__LINE__);
        return OMCI_VOIP_FAIL;
    }

    retryInterval = strtol(buf, NULL, 10);

    if ( 0 == retryInterval && ( EINVAL == errno || ERANGE == errno) ){
        return OMCI_VOIP_FAIL;
    }

	sip_agent_cfg_ptr->sipRegExpTime = retryInterval;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! retryInterval=%d\n",__FUNCTION__,__LINE__,retryInterval);
    return OMCI_VOIP_SUCC;

}
int setSipAgentCfgDataSIPReregTime(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
    char buf[20];
	uint32_t retryInterval;
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	
	retryInterval = sip_agent_cfg_ptr->sipRegExpTime;

    snprintf(buf, 20, "%u", retryInterval);

    if( 0 != omci_voip_set_re_reg_time(buf) ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_set_re_reg_time fail! \n",__FUNCTION__,__LINE__);
        return OMCI_VOIP_FAIL;
    }

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! retryInterval=%d\n",__FUNCTION__,__LINE__,retryInterval);
    return OMCI_VOIP_SUCC;

}
int getSipAgentCfgDataSIPStatus(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char buff[30];
	uint8_t  entryIdx = 0; // todo, how to get the current voip line?
	char status = 0;
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	
	
    if ( 0 != omci_voip_get_sip_status(buff, sizeof(buff), entryIdx)){
		 omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: tcapi_get status fail! \n",__FUNCTION__,__LINE__);
		 return OMCI_VOIP_FAIL;
	}

	 if ( 0 == strcmp(buff, VOIP_SIP_SZ_STATUTS_OK_INITIAL)   || 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_UP) 	  || 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_INITING)  || 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_REGING)   || 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_UNREGING) || 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_TESTING)  || 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_QUIESCENT)|| 
		  0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_DISABELED) )
	 {
		  status = VOIP_SIP_STATUTS_OK_INITIAL;
	 }else if (0 == strcmp(buff, VOIP_SIP_SZ_STATUTS_CONNECTED)){
		 status = VOIP_SIP_STATUTS_CONNECTED;
	 }else if (0 == strcmp(buff, VOIP_SIP_SZ_STATUTS_FAIL_ICMP_ERROR) || 
			   0 == strcmp(buff, VOIP_SIP_TR69_SZ_STATUS_ERROR)){
		 status = VOIP_SIP_STATUTS_FAIL_ICMP_ERROR;
	 }else if (0 == strcmp(buff, VOIP_SIP_SZ_STATUTS_FAIL_MALFORMED_RES)){
		 status = VOIP_SIP_STATUTS_FAIL_MALFORMED_RES;
	 }else if (0 == strcmp(buff, VOIP_SIP_SZ_STATUTS_FAIL_INADEQUATE_INFO_RES)){
		 status = VOIP_SIP_STATUTS_FAIL_INADEQUATE_INFO_RES;
	 }else if (0 == strcmp(buff, VOIP_SIP_SZ_STATUTS_FAIL_TIMEOUT)){
		 status = VOIP_SIP_STATUTS_FAIL_TIMEOUT;
	 }else{
		 omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "In Get_SipAgentCfgData_SIPStatus can't recognize status: %s\n", buff);
		 return OMCI_VOIP_FAIL;
	 }

	 sip_agent_cfg_ptr->sipStatus = status;
	 omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! status=%d\n",__FUNCTION__,__LINE__,status);
	 return OMCI_VOIP_SUCC;

}

int setSipAgentCfgDataTcpUdp(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
#if defined(TCSUPPORT_PON_IP_HOST)
	uint16_t ipHostIstId = 0;
	omci_tcp_udp_cfg_ptr tcp_udp_cfg_ptr=NULL;
#endif
	omci_sip_agent_cfg_ptr sip_agent_cfg_ptr=NULL;
	omci_me_info_t me_info_buf={0};

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	sip_agent_cfg_ptr = (omci_sip_agent_cfg_ptr)(me_info->attributes);	

	/*get address pointer  form 9.12.3 network address ME*/
	me_info_buf.class_id = OMCI_CLASS_ID_TCP_UDP_CFGDATA;
	me_info_buf.inst_id = sip_agent_cfg_ptr->tcpOrUdpPtr;
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	
#if defined(TCSUPPORT_PON_IP_HOST)
	tcp_udp_cfg_ptr = (omci_tcp_udp_cfg_ptr)(me_info_buf.attributes);
	
    ipHostIstId = tcp_udp_cfg_ptr->ipHostPointer;
	setWanInfo(WAN_IF_TYPE_SVC_LIST,ipHostIstId,WAN_SRV_VOICE_SRV);
#endif

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! \n",__FUNCTION__,__LINE__);
	return OMCI_VOIP_SUCC;

}
static void Parse_URL(IN_OUT char * buff /*Careful! Crash if NULL*/, 
          OUT char **  addr, OUT char ** port)
{
    OMCI_FUNC_TRACE_ENTER;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "String to Parse: %s\n", buff);
    
    *addr = buff;
    *port = NULL;
    
    char * delimter_pos = strchr(buff, ':');

    if ( NULL != delimter_pos )
    {
        * delimter_pos = '\0';
        * port = ++ delimter_pos;
    }
    OMCI_FUNC_TRACE_LEAVE;
}

  int Set_SipAgentCfgData_Addr_CfgManagerNode(omciVoipAttrType attrType,
    IN_OUT uint8_t * buff /*Careful! Crash if NULL*/, uint16_t portid, uint16_t entry_id)
{
    char * addr = NULL, *portPtr = NULL, portBuf[10]={0};
    char attrServerName[MAX_BUFFER_SIZE] = {0};
    char attrPortName[MAX_BUFFER_SIZE] = {0};
    char nodeName[MAX_BUFFER_SIZE] = {0};
    int port = 0;

    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] omciVoipAttrType=%d,portid=%d,entry_id=%d\n",
		__FUNCTION__,__LINE__,attrType,portid,entry_id);

    Parse_URL((char *)buff, &addr, &portPtr);
    if( portPtr != NULL)
        port = atoi(portPtr);
    else
        omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d] SET URL port is NULL\n",__FUNCTION__,__LINE__);
    if(port)
    {
    	//set local port
    	 if(entry_id > 0 && entry_id < 2)
    		sprintf(attrPortName, "%s%d", "LocalSIPPort", entry_id);
    	 else if(entry_id == 0)
    		sprintf(attrPortName, "%s", "LocalSIPPort");
    	 else
    		return OMCI_VOIP_FAIL;

    	sprintf(portBuf, "%d", portid);
    	omci_tcapi_set(OMCI_VOIP_BASIC_COMMON, attrPortName, portBuf);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] LocalSIPPort = %s\n",__FUNCTION__,__LINE__,portBuf);
    }
    else
		port = portid;

    sprintf(portBuf, "%d", port);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] port = %d\n",__FUNCTION__,__LINE__,port);

    if(entry_id > 0 && entry_id < 2)
    {
        switch(attrType){
        case OMCI_VOIP_ATTR_REGISTER:
            sprintf(attrServerName, "%s%d", "RegistrarServer", entry_id);
            sprintf(attrPortName, "%s%d", "RegistrarServerPort", entry_id);
            break;
        case OMCI_VOIP_ATTR_PROXY:
            sprintf(attrServerName, "%s%d", "SIPProxyAddr", entry_id);
            sprintf(attrPortName, "%s%d", "SIPProxyPort", entry_id);
            break;
        case OMCI_VOIP_ATTR_OUTBOUND:
            sprintf(attrServerName, "%s%d", "SIPOutboundProxyAddr", entry_id);
            sprintf(attrPortName, "%s%d", "SIPOutboundProxyPort", entry_id);
            break;
        default:
            omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] attrType:%d is invald.\n", 
                __FUNCTION__, __LINE__, attrType);
            return OMCI_VOIP_FAIL;
            break;

        }
    }
    else if(entry_id == 0){

        switch(attrType){
        case OMCI_VOIP_ATTR_REGISTER:
            sprintf(attrServerName, "%s", "RegistrarServer");
            sprintf(attrPortName, "%s", "RegistrarServerPort");
            break;
        case OMCI_VOIP_ATTR_PROXY:
            sprintf(attrServerName, "%s", "SIPProxyAddr");
            sprintf(attrPortName, "%s", "SIPProxyPort");
            break;
        case OMCI_VOIP_ATTR_OUTBOUND:
            sprintf(attrServerName, "%s", "SIPOutboundProxyAddr");
            sprintf(attrPortName, "%s", "SIPOutboundProxyPort");
            break;
        default:
            omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] attrType:%d is invald.\n", 
                __FUNCTION__, __LINE__, attrType);
            return OMCI_VOIP_FAIL;
        }
    }
    else{
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] entry_id:%d is invald.\n", 
            __FUNCTION__, __LINE__, entry_id);
        return OMCI_VOIP_FAIL;
    }
    if (NULL != addr){
        if ( 0 != omci_tcapi_set(OMCI_VOIP_BASIC_COMMON, attrServerName, addr) ){
            return OMCI_VOIP_FAIL;
        }
    }


    if ( 0 != omci_tcapi_set(OMCI_VOIP_BASIC_COMMON, attrPortName, portBuf) ){
        return OMCI_VOIP_FAIL;
    }

    sprintf(nodeName, "%s", OMCI_VOIP_BASIC);
    if( 0 != omci_adpt_delay_omci_commit_node(nodeName) )
        return OMCI_VOIP_FAIL;

    return OMCI_VOIP_SUCC;

}

static int setSipAgentServersForSipUserData(uint16_t instId, uint16_t entryId)
{
    uint16_t addressInstid = 0;
    uint16_t agentInstid = 0;
    uint16_t proxySvrInstId = 0;
    uint16_t outboundProxyInsId = 0;
    uint16_t serverPort = 0;
    int ret = 0;
    omci_me_info_t me_info_tmp = {0};
    omci_sip_user_data_ptr sip_user_data = NULL;
    omci_sip_agent_cfg_ptr sip_agent = NULL;
    omci_tcp_udp_cfg_ptr tcp_udp = NULL;
	omci_network_address_ptr network_addr = NULL;
	omci_large_string_ptr large_str = NULL;
    
    /*get 9.9.2 SIP agent pointer arribute.*/
    me_info_tmp.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
	me_info_tmp.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	if(me_info_tmp.attributes == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	sip_user_data = (omci_sip_user_data_ptr)me_info_tmp.attributes;
    agentInstid = sip_user_data->sipAgentPtr;

    /* get SIP server port  form 9.9.3 SIP agent config data ME */
    me_info_tmp.class_id = OMCI_CLASS_ID_SIP_AGENT_CONFIG_DATA;
	me_info_tmp.inst_id = agentInstid;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	if(me_info_tmp.attributes == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
    sip_agent = (omci_sip_agent_cfg_ptr)me_info_tmp.attributes;
    /*get SIP Registrar server IP  form 9.9.3 SIP agent config data ME */
    addressInstid = sip_agent->sipRegistrar;
    /*get Proxy server address pointer  form 9.12.4 authentication security method ME*/
    proxySvrInstId = sip_agent->proxySrvAddrPtr;    
    outboundProxyInsId = sip_agent->outbndProxyAddrPtr;


    /* get SIP port  form 9.4.3 TCP/UDP config data ME */
    me_info_tmp.class_id = OMCI_CLASS_ID_TCP_UDP_CFGDATA;
	me_info_tmp.inst_id = sip_agent->tcpOrUdpPtr;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	if(me_info_tmp.attributes == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
    tcp_udp = (omci_tcp_udp_cfg_ptr)me_info_tmp.attributes;
    serverPort = tcp_udp->portId;

    /* get large string ME from network address ME */
    me_info_tmp.class_id = OMCI_CLASS_ID_NETWORK_ADDRESS;
	me_info_tmp.inst_id = addressInstid;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
	}else{
    	if(me_info_tmp.attributes == NULL)
    	{
    	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
    		return OMCI_VOIP_FAIL;
    	}
        network_addr = (omci_network_address_ptr)me_info_tmp.attributes;
    

        me_info_tmp.class_id = OMCI_CLASS_ID_LARGE_STRING;
    	me_info_tmp.inst_id = network_addr->addressPointer;
    	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
    		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
    	}else{
            if(me_info_tmp.attributes == NULL)
        	{
        	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
        		return OMCI_VOIP_FAIL;
        	}
            large_str = (omci_large_string_ptr)me_info_tmp.attributes;
            /* isntance id of ME sip agent config data, for Alphion is 0,1,2... but huawei OLT is 1,2,3... */
            ret = Set_SipAgentCfgData_Addr_CfgManagerNode(OMCI_VOIP_ATTR_REGISTER, (uint8_t *)large_str->all_part.part, serverPort, entryId);
            if(ret != 0){
               return OMCI_VOIP_FAIL;
            }
        }
    }

    /*  set proxy server.  */
    me_info_tmp.class_id = OMCI_CLASS_ID_LARGE_STRING;
	me_info_tmp.inst_id = proxySvrInstId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
	}else{
        if(me_info_tmp.attributes == NULL)
    	{
    	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
    		return OMCI_VOIP_FAIL;
    	}
        large_str = (omci_large_string_ptr)me_info_tmp.attributes;

        /* isntance id of ME sip agent config data, for Alphion is 0,1,2... but huawei OLT is 1,2,3... */
        ret = Set_SipAgentCfgData_Addr_CfgManagerNode(OMCI_VOIP_ATTR_PROXY, (uint8_t *)large_str->all_part.part, serverPort, entryId);
        if(ret != 0){
            return OMCI_VOIP_FAIL;
        }
    }
    /*  set outbound proxy server.  */
    /*get Outbound proxy address pointer  form 9.12.4 authentication security method ME*/
	if(outboundProxyInsId != 0xFFFF){
	    me_info_tmp.class_id = OMCI_CLASS_ID_LARGE_STRING;
		me_info_tmp.inst_id = outboundProxyInsId;
		if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		}else{
    	    if(me_info_tmp.attributes == NULL)
    		{
    		    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
    			return OMCI_VOIP_FAIL;
    		}
    	    large_str = (omci_large_string_ptr)me_info_tmp.attributes;

    	    /* isntance id of ME sip agent config data, for Alphion is 0,1,2... but huawei OLT is 1,2,3... */
    	    ret = Set_SipAgentCfgData_Addr_CfgManagerNode(OMCI_VOIP_ATTR_OUTBOUND, (uint8_t *)large_str->all_part.part, serverPort, entryId);
    	    if(ret != 0){
    	        return OMCI_VOIP_FAIL;
    	    }
        }
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d]Outbound proxy address poniter is 0xFFFF(Reserved ME Instance).\n",__FUNCTION__,__LINE__);
	}

    return OMCI_VOIP_SUCC;

}

int omci_me_sip_agent_cfg_create_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: Enter\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

	omci_me_general_create_op(me_entry, me_info);

	omci_set_voip_basic_comm();

	return OMCI_VOIP_SUCC;
}

int omci_me_sip_agent_cfg_del_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: Enter\n",__FUNCTION__,__LINE__);
	if((NULL == me_entry)||(NULL == me_info)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}

	if(omci_voip_reset_sip_agent_cfg() != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s]:omci_voip_reset_sip_agent_cfg fail ![%d]\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	return OMCI_VOIP_SUCC;
}

int getVOIPMediaProFaxMode(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char tempBuffer[MAX_BUFFER_SIZE+1] = {0};
	uint8_t faxMode= 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	omci_voip_get_fax_mode(tempBuffer, sizeof(tempBuffer));

	if(strcmp(tempBuffer,OMCI_VOIP_ATTR_ENABLE_NAME)== 0){
		faxMode = OMCI_FAX_MODE_T38;
	}else{
		faxMode = OMCI_FAX_MODE_PASSTHRU;
	}

	voip_media_prof_ptr->faxMode = faxMode;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! faxMode=%d\n",__FUNCTION__,__LINE__,faxMode);
	return OMCI_VOIP_SUCC;

}
int setVOIPMediaProFaxMode(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char tempBuffer[MAX_BUFFER_SIZE+1] = {0};
	uint8_t faxMode= 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	faxMode =voip_media_prof_ptr->faxMode;
	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	if(faxMode == OMCI_FAX_MODE_PASSTHRU){
		strcpy(tempBuffer,OMCI_VOIP_ATTR_DISABLE_NAME);
	}else if(faxMode == OMCI_FAX_MODE_T38){
		strcpy(tempBuffer,OMCI_VOIP_ATTR_ENABLE_NAME);
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: faxMode invalid\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;	
	}	
	
	if(omci_voip_set_fax_mode(tempBuffer) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_fax_mode fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;	
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! faxMode=%d\n",__FUNCTION__,__LINE__,faxMode);
	return OMCI_VOIP_SUCC;

}
static int getVOIPMediaProCodecSele(omci_me_info_ptr me_info,  uint8_t index){
	uint8_t codecType = 0;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	if(OMCI_MEDIA_1ST == index ||OMCI_MEDIA_2ND == index||OMCI_MEDIA_3RD == index||OMCI_MEDIA_4TH == index){
		memset(tempBuffer, 0, MAX_BUFFER_SIZE);
		omci_voip_get_codec_select(tempBuffer, sizeof(tempBuffer), index);
		
		if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_PCMA) == 0){
			codecType = OMCI_MEDIA_CODEC_PCMA;
		}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_PCMU) == 0){
			codecType = OMCI_MEDIA_CODEC_PCMU;
		}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G722) == 0){
			codecType = OMCI_MEDIA_CODEC_G722;
		}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G723) == 0){
			codecType = OMCI_MEDIA_CODEC_G723;	
		}else if(strstr(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G726) != NULL){
			codecType = OMCI_MEDIA_CODEC_G726;
		}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G729) == 0){
			codecType = OMCI_MEDIA_CODEC_G729;
		}else{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: invalid tempBuffer=%s\n",__FUNCTION__,__LINE__,tempBuffer);
			return OMCI_VOIP_FAIL;
		}
	}

	switch(index){
		case OMCI_MEDIA_1ST:
			voip_media_prof_ptr->codecSelection1 = codecType; 
			break;
		case OMCI_MEDIA_2ND:
			voip_media_prof_ptr->codecSelection2 = codecType; 
			break;
		case OMCI_MEDIA_3RD:
			voip_media_prof_ptr->codecSelection3 = codecType; 
			break;
		case OMCI_MEDIA_4TH:
			voip_media_prof_ptr->codecSelection4 = codecType; 
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] index = %d, invalid!\n",__FUNCTION__,__LINE__,index);
			return OMCI_VOIP_FAIL;
	}
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! codecType=%d\n",__FUNCTION__,__LINE__,codecType);
	return OMCI_VOIP_SUCC;
}


static int setVOIPMediaProCodecSele(omci_me_info_ptr me_info,  uint8_t index){
	int ret = OMCI_VOIP_FAIL;
	uint8_t codecType= 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	
	switch(index){
		case OMCI_MEDIA_1ST:
			codecType = voip_media_prof_ptr->codecSelection1; 
			break;
		case OMCI_MEDIA_2ND:
			codecType = voip_media_prof_ptr->codecSelection2; 
			break;
		case OMCI_MEDIA_3RD:
			codecType = voip_media_prof_ptr->codecSelection3;  
			break;
		case OMCI_MEDIA_4TH:
			codecType = voip_media_prof_ptr->codecSelection4; 
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] index = %d, invalid!\n",__FUNCTION__,__LINE__,index);
			return OMCI_VOIP_FAIL;
	}

	if(omci_voip_set_codec_select(codecType,index) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_codec_select fail !\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, codecType=%d,index=%d!\n",__FUNCTION__,__LINE__,ret,codecType,index);
	return ret;
}

static int getVOIPMediaProPktPeriodSele(omci_me_info_ptr me_info,  uint8_t index){
	int ret = OMCI_VOIP_FAIL;
	uint8_t periodMs = 0;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	if(OMCI_MEDIA_1ST == index ||OMCI_MEDIA_2ND == index||OMCI_MEDIA_3RD == index||OMCI_MEDIA_4TH == index){
		omci_voip_get_pack_period_select(tempBuffer, sizeof(tempBuffer), index);
		
		periodMs = atoi(tempBuffer);

		if((periodMs < MIN_OMCI_MEDIA_PKT_PERIOD_VAL) || (periodMs > MAX_OMCI_MEDIA_PKT_PERIOD_VAL)){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] periodMs=%d(10-30),error\n",__FUNCTION__,__LINE__,periodMs);
			goto end;
		}
	}
	
	switch(index){
		case OMCI_MEDIA_1ST:
			voip_media_prof_ptr->pktPeriodSelection1 = periodMs; 
			break;
		case OMCI_MEDIA_2ND:
			voip_media_prof_ptr->pktPeriodSelection2 = periodMs; 
			break;
		case OMCI_MEDIA_3RD:
			voip_media_prof_ptr->pktPeriodSelection3 = periodMs; 
			break;
		case OMCI_MEDIA_4TH:
			voip_media_prof_ptr->pktPeriodSelection4 = periodMs; 
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] index = %d, invalid!\n",__FUNCTION__,__LINE__,index);
			return OMCI_VOIP_FAIL;
	}

	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, periodMs=%d,index=%d!\n",__FUNCTION__,__LINE__,ret,periodMs,index);
	return ret;
}

static int setVOIPMediaProPktPeriodSele(omci_me_info_ptr me_info,  uint8_t index){
	int ret = OMCI_VOIP_FAIL;	
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	uint8_t periodMs = 0;
	uint8_t codecType= 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;
	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	
	switch(index){
		case OMCI_MEDIA_1ST:
			periodMs = voip_media_prof_ptr->pktPeriodSelection1; 
			codecType = voip_media_prof_ptr->codecSelection1; 
			break;
		case OMCI_MEDIA_2ND:
			periodMs = voip_media_prof_ptr->pktPeriodSelection2; 
			codecType = voip_media_prof_ptr->codecSelection2; 
			break;
		case OMCI_MEDIA_3RD:
			periodMs = voip_media_prof_ptr->pktPeriodSelection3;  
			codecType = voip_media_prof_ptr->codecSelection3; 
			break;
		case OMCI_MEDIA_4TH:
			periodMs = voip_media_prof_ptr->pktPeriodSelection4; 
			codecType = voip_media_prof_ptr->codecSelection4; 
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] index = %d, invalid!\n",__FUNCTION__,__LINE__,index);
			return OMCI_VOIP_FAIL;
	}

	if((periodMs < MIN_OMCI_MEDIA_PKT_PERIOD_VAL) || (periodMs > MAX_OMCI_MEDIA_PKT_PERIOD_VAL)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] periodMs=%d(10-30),error!",__FUNCTION__,__LINE__,periodMs);
		goto end;
	}

	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	sprintf(tempBuffer, "%d", periodMs);	

	if(omci_voip_set_pack_period_select(codecType,tempBuffer, index) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail !\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, periodMs=%d,index=%d!\n",__FUNCTION__,__LINE__,ret,periodMs,index);
	return ret;

}

static int getVOIPMediaProSlience(omci_me_info_ptr me_info,  uint8_t index){
	int ret = OMCI_VOIP_FAIL;
	uint8_t silenceFlag = 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	omci_voip_get_silence_suppress(&silenceFlag, index);
	switch(index){
		case OMCI_MEDIA_1ST:
			voip_media_prof_ptr->silenceSuppression1= silenceFlag; 
			break;
		case OMCI_MEDIA_2ND:
			voip_media_prof_ptr->silenceSuppression2 = silenceFlag; 
			break;
		case OMCI_MEDIA_3RD:
			voip_media_prof_ptr->silenceSuppression3 = silenceFlag; 
			break;
		case OMCI_MEDIA_4TH:
			voip_media_prof_ptr->silenceSuppression4 = silenceFlag; 
			break;
		default:
			goto end;
	}

	ret = OMCI_VOIP_SUCC;
	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, silenceFlag=%d,index=%d!\n",__FUNCTION__,__LINE__,ret,silenceFlag,index);
	return ret;
}

static int setVOIPMediaProSlience(omci_me_info_ptr me_info,  uint8_t index){
	int ret = OMCI_VOIP_FAIL;	
	uint8_t silenceFlag = 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	
	switch(index){
		case OMCI_MEDIA_1ST:
			silenceFlag = voip_media_prof_ptr->silenceSuppression1; 
			break;
		case OMCI_MEDIA_2ND:
			silenceFlag = voip_media_prof_ptr->silenceSuppression2; 
			break;
		case OMCI_MEDIA_3RD:
			silenceFlag = voip_media_prof_ptr->silenceSuppression3;  
			break;
		case OMCI_MEDIA_4TH:
			silenceFlag = voip_media_prof_ptr->silenceSuppression4; 
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] index = %d, invalid!\n",__FUNCTION__,__LINE__,index);
			return OMCI_VOIP_FAIL;
	}

	if(omci_voip_set_silence_suppress(silenceFlag, index) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_silence_suppress fail !\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, silenceFlag=%d,index=%d!\n",__FUNCTION__,__LINE__,ret,silenceFlag,index);
	return ret;

}

int getVOIPMediaProCodecSele1st(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProCodecSele(me_info,OMCI_MEDIA_1ST);
}
int setVOIPMediaProCodecSele1st(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProCodecSele(me_info,OMCI_MEDIA_1ST);
}
int getVOIPMediaProPktPeriodSele1st(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_1ST);
}
int setVOIPMediaProPktPeriodSele1st(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_1ST);
}
int getVOIPMediaProSlience1st(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProSlience(me_info,OMCI_MEDIA_1ST);
}
int setVOIPMediaProSlience1st(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProSlience(me_info,OMCI_MEDIA_1ST);
}
int getVOIPMediaProCodecSele2nd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProCodecSele(me_info,OMCI_MEDIA_2ND);
}
int setVOIPMediaProCodecSele2nd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProCodecSele(me_info,OMCI_MEDIA_2ND);
}
int getVOIPMediaProPktPeriodSele2nd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_2ND);
}
int setVOIPMediaProPktPeriodSele2nd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_2ND);
}
int getVOIPMediaProSlience2nd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProSlience(me_info,OMCI_MEDIA_2ND);
}
int setVOIPMediaProSlience2nd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
#if 0
	return setVOIPMediaProSlience(me_info,OMCI_MEDIA_2ND);
#else
    return 0;
#endif
}
int getVOIPMediaProCodecSele3rd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProCodecSele(me_info,OMCI_MEDIA_3RD);
}
int setVOIPMediaProCodecSele3rd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProCodecSele(me_info,OMCI_MEDIA_3RD);
}
int getVOIPMediaProPktPeriodSele3rd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_3RD);
}
int setVOIPMediaProPktPeriodSele3rd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_3RD);
}
int getVOIPMediaProSlience3rd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProSlience(me_info,OMCI_MEDIA_3RD);
}
int setVOIPMediaProSlience3rd(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProSlience(me_info,OMCI_MEDIA_3RD);
}
int getVOIPMediaProCodecSele4th(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProCodecSele(me_info,OMCI_MEDIA_4TH);
}
int setVOIPMediaProCodecSele4th(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProCodecSele(me_info,OMCI_MEDIA_4TH);
}
int getVOIPMediaProPktPeriodSele4th(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_4TH);
}
int setVOIPMediaProPktPeriodSele4th(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProPktPeriodSele(me_info,OMCI_MEDIA_4TH);
}
int getVOIPMediaProSlience4th(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return getVOIPMediaProSlience(me_info,OMCI_MEDIA_4TH);
}
int setVOIPMediaProSlience4th(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	return setVOIPMediaProSlience(me_info,OMCI_MEDIA_4TH);
}

int getVOIPMediaProOOBDtmf(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint8_t dtmfFlag = 0;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	omci_voip_get_oob_dtmf(tempBuffer,sizeof(tempBuffer));

	if(strcmp(tempBuffer,OMCI_MEDIA_DTMF_MODE_RFC2833) == 0){
		dtmfFlag = OMCI_VOIP_PARA_ENABLE;
	}else{
		dtmfFlag = OMCI_VOIP_PARA_DISABLE;
	}
	
	voip_media_prof_ptr->oobDtmf = dtmfFlag;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! dtmfFlag=%d\n",__FUNCTION__,__LINE__,dtmfFlag);
    return OMCI_VOIP_SUCC;

}
int setVOIPMediaProOOBDtmf(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	uint8_t dtmfFlag = 0;
	omci_voip_media_prof_ptr voip_media_prof_ptr=NULL;

	if(me_info == NULL || me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_media_prof_ptr = (omci_voip_media_prof_ptr)(me_info->attributes);	

	dtmfFlag = voip_media_prof_ptr->oobDtmf;
	if(dtmfFlag == OMCI_VOIP_PARA_ENABLE){
		strcpy(tempBuffer,OMCI_MEDIA_DTMF_MODE_RFC2833);
	}else{
		strcpy(tempBuffer,OMCI_MEDIA_DTMF_MODE_INBAND);
	}
	
	if(omci_voip_set_oob_dtmf(tempBuffer) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_oob_dtmf fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! dtmfFlag=%d\n",__FUNCTION__,__LINE__,dtmfFlag);
    return OMCI_VOIP_SUCC;

}

int getNetDialPlanTblDialNumber(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t maxNum = 0;
	uint16_t tableLength=0;
	omci_net_dial_plan_tab_ptr net_dial_plan_tab_ptr=NULL;
	omci_net_dial_plan_tab_ptr old_net_dial_plan_tab_ptr=NULL;
	omci_me_info_t me_info_buf = {0};

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	net_dial_plan_tab_ptr = (omci_net_dial_plan_tab_ptr)(me_info->attributes);	

	/*get dial plan table size and get max number in table*/
	me_info_buf.class_id = OMCI_CLASS_ID_NETWORK_DIAL_PLAN_TBL;
	me_info_buf.inst_id = net_dial_plan_tab_ptr->meId;
	me_info_buf.mask = 0x8000 >> 5; //dial plan table
	if(omci_attr_get_one_table_attr_by_mask(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	old_net_dial_plan_tab_ptr = (omci_net_dial_plan_tab_ptr)(me_info_buf.attributes);
	tableLength = old_net_dial_plan_tab_ptr->dialPlanTab.len;
	maxNum = tableLength/OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
		
	net_dial_plan_tab_ptr->dialPlanNum = maxNum;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! dialPlanNum=%d\n",__FUNCTION__,__LINE__,maxNum);
    return OMCI_VOIP_SUCC;

}
int setNetDialPlanTblDialFormat(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint8_t format = 0;
	omci_net_dial_plan_tab_ptr net_dial_plan_tab_ptr=NULL;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	net_dial_plan_tab_ptr = (omci_net_dial_plan_tab_ptr)(me_info->attributes);	

	format = net_dial_plan_tab_ptr->dialPlanFormat;
	switch(format){
		case OMCI_VOIP_NET_DIAL_PLAN_TBL_FORMAT_NO_DEFINED:
		case OMCI_VOIP_NET_DIAL_PLAN_TBL_FORMAT_H248:
		case OMCI_VOIP_NET_DIAL_PLAN_TBL_FORMAT_NSC:
		case OMCI_VOIP_NET_DIAL_PLAN_TBL_FORMAT_VENDOR:
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: format=%d, fail",__FUNCTION__,__LINE__,format);
			return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! format=%d\n",__FUNCTION__,__LINE__,format);
    return OMCI_VOIP_SUCC;

}

int setNetDialPlanTblDialTbl(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_SUCC;
	char *tableEntrVal = NULL;
	char *temp2_ptr = NULL;
	char *entryValue_ptr = NULL;
	uint32_t tableSize= 0;
	uint32_t length = 0;
	uint32_t tempU32 = 0;
	uint8_t findFlag = OMCI_VOIP_NO_FIND;
	char action = OMCI_VOIP_NET_DIAL_PLAN_TBL_ADD_ACTION;
	uint16_t maxNum =0, currNum = 0;
    uint8_t dialPlanId = 0;
	omci_net_dial_plan_tab_ptr net_dial_plan_tab_ptr=NULL;
	omci_net_dial_plan_tab_ptr old_net_dial_plan_tab_ptr=NULL;
	omci_me_info_t me_info_buf = {0};

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	net_dial_plan_tab_ptr = (omci_net_dial_plan_tab_ptr)(me_info->attributes);	
	
	/*1.3 get action type*/
	tableEntrVal = net_dial_plan_tab_ptr->dialPlanTab.buf;
	action = *(tableEntrVal+1);
	switch(action){
		case OMCI_VOIP_NET_DIAL_PLAN_TBL_ADD_ACTION:
		case OMCI_VOIP_NET_DIAL_PLAN_TBL_DEL_ACTION:
			break;
		default:
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: setNetDialPlanTblDialTbl-> action=%d , fail",__FUNCTION__,__LINE__,action);
			goto end;
	}
	
	
	/*1.4 get current table content*/
	me_info_buf.class_id = OMCI_CLASS_ID_NETWORK_DIAL_PLAN_TBL;
	me_info_buf.inst_id = net_dial_plan_tab_ptr->meId;
	me_info_buf.mask = 0x8000 >> 5; //dial plan table
	if(omci_attr_get_one_table_attr_by_mask(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	old_net_dial_plan_tab_ptr = (omci_net_dial_plan_tab_ptr)(me_info_buf.attributes);
	tableSize = old_net_dial_plan_tab_ptr->dialPlanTab.len;
	temp2_ptr = old_net_dial_plan_tab_ptr->dialPlanTab.buf;

	/*1.5 search record*/
	findFlag = OMCI_VOIP_NO_FIND;
	length = OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;	
	while(temp2_ptr  != NULL){
		currNum++; //calculate current record number in table
		if(*temp2_ptr == *tableEntrVal){
			findFlag = OMCI_VOIP_FIND;//find
		}
		length += OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
		if(length > tableSize){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: length(%d) > tableSize(%d)\n",__FILE__, __LINE__,length,tableSize);
			break;
		}
		temp2_ptr += OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
	}		
	
	/*2.1 
	**find and add  rule then return success,
	**no find and delete rule then return success.
	*/
	if(findFlag == OMCI_VOIP_FIND){//find
		if(action == OMCI_VOIP_NET_DIAL_PLAN_TBL_ADD_ACTION){// add entry
			ret = OMCI_VOIP_SUCC;
			goto end;
		}
	}else{ //no find
		if(action == OMCI_VOIP_NET_DIAL_PLAN_TBL_DEL_ACTION){ //del entry
			ret = OMCI_VOIP_SUCC;
			goto end;		
			}
	}

	/*2.2 get max number in attribute*/
	maxNum = old_net_dial_plan_tab_ptr->dialPlanTabMaxSize;

	/*3. prepare value for table*/
	/*3.1 malloc new space*/
	entryValue_ptr = malloc(tableSize+OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN);			
	if(entryValue_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: entryValue_ptr calloc failure",__FILE__, __LINE__);
		goto end;		
	}

	/*3.2 fill new space to table*/
	if(action == OMCI_VOIP_NET_DIAL_PLAN_TBL_DEL_ACTION){//del entry
		/*handle table in OMCI*/
		temp2_ptr = old_net_dial_plan_tab_ptr->dialPlanTab.buf;
		
		/*search record*/
		length = OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
		while(temp2_ptr  != NULL){		
			if(*temp2_ptr == *tableEntrVal){ //find and delete entry in  table	
				/*copy first part*/
				tempU32 = length - OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;					
				tableEntrVal = entryValue_ptr;
				memcpy(tableEntrVal, old_net_dial_plan_tab_ptr->dialPlanTab.buf, tempU32);
				tableEntrVal += tempU32;
				/*copy second part*/
				temp2_ptr = old_net_dial_plan_tab_ptr->dialPlanTab.buf +length;
				tempU32 = old_net_dial_plan_tab_ptr->dialPlanTab.len - length;// copy length
				if(tempU32 > 0){
					memcpy(tableEntrVal, temp2_ptr, tempU32);
				}
				
				tableSize -= OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
				break;
			}
			length += OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
			if(length > old_net_dial_plan_tab_ptr->dialPlanTab.len) {//no find and no happen
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: del entry and no find entry, fail",__FILE__, __LINE__);
				break;
			}
			temp2_ptr += OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;
		}		
	}
	else {// add entry 	
		/*overflow in this table*/
		// if(currNum >= maxNum){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: currNum(%d)>=maxNum(%d), fail!",__FILE__, __LINE__,currNum, maxNum);
		// 	goto end;
		// }
		
		/*handle table in OMCI*/
		if(tableSize > 0){
			memcpy(entryValue_ptr, old_net_dial_plan_tab_ptr->dialPlanTab.buf, tableSize);
		}
		memcpy(entryValue_ptr+tableSize, tableEntrVal, OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN);
		tableSize += OMCI_VOIP_NET_DIAL_PLAN_TBL_RECORD_LEN;

		dialPlanId = *entryValue_ptr;
		omci_voip_set_digital_map((char *)(entryValue_ptr+2),dialPlanId);
	}
	
end:
	if(entryValue_ptr != NULL){
		free(entryValue_ptr);
		entryValue_ptr = NULL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d, tableSize=%d\n",__FUNCTION__,__LINE__,ret,tableSize);
    return ret;
}

int getVoIPStatusDataCodecsUsed(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t codecType = 0;
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	uint8_t index = 0; 
	uint8_t index_pri = 0;
	omci_voip_line_status_ptr voip_line_status_ptr=NULL;

	if(me_info == NULL || me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr = (omci_voip_line_status_ptr)(me_info->attributes);	

	for(index=0; index<OMCI_MEDIA_NUM; index++){
		omci_voip_get_codec_used(&index_pri, index);
		if(index_pri == OMCI_VOIP_LINE_USED_CODEC)
			break;
	}
	
	memset(tempBuffer, 0, MAX_BUFFER_SIZE);
	omci_voip_get_codec_select(tempBuffer, sizeof(tempBuffer), index);
	if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_PCMA) == 0){
		codecType = OMCI_MEDIA_CODEC_PCMA;
	}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_PCMU) == 0){
		codecType = OMCI_MEDIA_CODEC_PCMU;
	}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G722) == 0){
		codecType = OMCI_MEDIA_CODEC_G722;
	}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G723) == 0){
		codecType = OMCI_MEDIA_CODEC_G723;	
	}else if(strstr(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G726) != NULL){
		codecType = OMCI_MEDIA_CODEC_G726;
	}else if(strcmp(tempBuffer,OMCI_MEDIA_SIPSUPPORTED_CODECS_G729) == 0){
		codecType = OMCI_MEDIA_CODEC_G729;
	}else{
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr->voipCodecUsed = codecType;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! voipCodecUsed=%d\n",__FUNCTION__,__LINE__,codecType);
    return OMCI_VOIP_SUCC;	
}
int getVoIPLineStatusVoiceServerStatus(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	omci_voip_ser_status_t ser_status = 0;
	omci_voip_line_status_ptr voip_line_status_ptr=NULL;

	if(me_info == NULL || me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr = (omci_voip_line_status_ptr)(me_info->attributes);	
	omci_voip_get_voice_server_status(&ser_status, 0);

	voip_line_status_ptr->voipVoiceSrvStatus= ser_status;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! voipVoiceSrvStatus=%d\n",__FUNCTION__,__LINE__,ser_status);
    return OMCI_VOIP_SUCC;	

}
int getVoIPLineStatusPortSessionType(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	omci_voip_port_ses_type_t port_sess_type = 0;
	omci_voip_line_status_ptr voip_line_status_ptr=NULL;

	if(me_info == NULL || me_info->attributes == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}
	voip_line_status_ptr = (omci_voip_line_status_ptr)(me_info->attributes);	
	omci_voip_get_port_session_type(&port_sess_type, 0);

	voip_line_status_ptr->voipPortSessionType= (uint8_t)port_sess_type;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! voipPortSessionType=%d\n",__FUNCTION__,__LINE__,port_sess_type);
    return OMCI_VOIP_SUCC;	

}
int getVoIPLineStatusCall1PacketPeriod(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	omci_voip_line_status_ptr voip_line_status_ptr=NULL;
	uint16_t tmp = 0;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr = (omci_voip_line_status_ptr)(me_info->attributes);	

	if(0 != omci_voip_get_packet_period(&tmp, OMCI_VOIP_CALL_PACKET_PERIOD_ONE)){
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr->voipCall1PktPeriod = tmp;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! voipCall1PktPeriod=%d\n",__FUNCTION__,__LINE__,voip_line_status_ptr->voipCall1PktPeriod);
    return OMCI_VOIP_SUCC;	
}
int getVoIPLineStatusCall2PacketPeriod(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	omci_voip_line_status_ptr voip_line_status_ptr=NULL;
	uint16_t tmp = 0;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr = (omci_voip_line_status_ptr)(me_info->attributes);	

	if(0 != omci_voip_get_packet_period(&tmp, OMCI_VOIP_CALL_PACKET_PERIOD_TWO)){
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr->voipCall2PktPeriod = tmp;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! voipCall2PktPeriod=%d\n",__FUNCTION__,__LINE__,voip_line_status_ptr->voipCall2PktPeriod);
	return OMCI_VOIP_SUCC;

}
int getVoIPLineState(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	omci_voip_line_status_ptr voip_line_status_ptr=NULL;
	omci_voip_line_state_t line_state=0;

	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr = (omci_voip_line_status_ptr)(me_info->attributes);

	if(0 != omci_voip_get_line_state(&line_state, (me_info->inst_id & 0xFF)-1)){
		return OMCI_VOIP_FAIL;
	}

	voip_line_status_ptr->voipLineState = (uint8_t)line_state;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! voipLineState=%d\n",__FUNCTION__,__LINE__,voip_line_status_ptr->voipLineState);
	return OMCI_VOIP_SUCC;

}

int setMGCCfgDataPriMGC(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{	
	uint16_t networkinstId = 0;
	omci_mgc_cfg_data_ptr mgc_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	mgc_cfg_data_ptr = (omci_mgc_cfg_data_ptr)(me_info->attributes);	

	/*get network address ME instance id*/
	networkinstId = mgc_cfg_data_ptr->primaryMgc;

	if(setMgcInfo(networkinstId, OMCI_H248_PRIMARY_ATTR_INDEX) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:setMgcInfo fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! networkinstId=%d\n",__FUNCTION__,__LINE__,networkinstId);
	return OMCI_VOIP_SUCC;

}
int setMGCCfgDataSecMGC(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t networkinstId = 0;
	omci_mgc_cfg_data_ptr mgc_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	mgc_cfg_data_ptr = (omci_mgc_cfg_data_ptr)(me_info->attributes);	

	/*get network address ME instance id*/
	networkinstId = mgc_cfg_data_ptr->secondaryMgc;

	if(setMgcInfo(networkinstId, OMCI_H248_SECNDARY_ATTR_INDEX) != OMCI_VOIP_SUCC){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:setMgcInfo fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! networkinstId=%d\n",__FUNCTION__,__LINE__,networkinstId);
	return OMCI_VOIP_SUCC;

}
int getMGCCfgDataDevId(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_mgc_cfg_data_ptr mgc_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	mgc_cfg_data_ptr = (omci_mgc_cfg_data_ptr)(me_info->attributes);	

	omci_voip_get_term_id_base(tempBuffer ,sizeof(tempBuffer));

	memcpy(mgc_cfg_data_ptr->terminationIdbase, tempBuffer, omci_attr->attriLen);	

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! terminationIdbase=%s\n",__FUNCTION__,__LINE__,tempBuffer);
	return OMCI_VOIP_SUCC;

}
int setMGCCfgDataDevId(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char tempBuffer[MAX_BUFFER_SIZE] = {0};
	omci_mgc_cfg_data_ptr mgc_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	mgc_cfg_data_ptr = (omci_mgc_cfg_data_ptr)(me_info->attributes);
	
	if(omci_voip_set_term_id_base(mgc_cfg_data_ptr->terminationIdbase) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_term_id_base fail !\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	memcpy(tempBuffer, mgc_cfg_data_ptr->terminationIdbase,omci_attr->attriLen);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! terminationIdbase=%s\n",__FUNCTION__,__LINE__,tempBuffer);
	return OMCI_VOIP_SUCC;

}

int getVOIPCfgDataAvaiProto(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint8_t protocol = OMCI_VOIP_CFG_DATA_SIGNALING_PROTOCOLS_NONE;
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info->attributes);

	omci_voip_get_avail_signal_protoc(&protocol);

	voip_cfg_data_ptr->availableSignalProtocols = protocol;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! availableSignalProtocols=%d\n",__FUNCTION__,__LINE__,protocol);
	return OMCI_VOIP_SUCC;

}
int getVOIPCfgDataProtoUsed(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;	
	uint8_t protocol = OMCI_VOIP_CFG_DATA_PROTOCOLS_USED_NONE;
	omci_me_info_t me_info_buf={0};
	omci_voip_cfg_data_ptr old_voip_cfg_data_ptr=NULL;
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info->attributes);

	if(omci_voip_get_signal_protocol_used(&protocol) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_get_signal_protocol_used fail.\n",__FILE__, __LINE__);
		goto end;
	}

	me_info_buf.class_id = me_info->class_id;
	me_info_buf.inst_id = me_info->inst_id;
	if(omci_attr_get_old_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		goto end;
	}
	old_voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info_buf.attributes);

	if(old_voip_cfg_data_ptr->availableSignalProtocols != OMCI_VOIP_CFG_DATA_PROTOCOLS_USED_NO_OMCI){
		voip_cfg_data_ptr->availableSignalProtocols = protocol;
	}else {
		voip_cfg_data_ptr->availableSignalProtocols = OMCI_VOIP_CFG_DATA_PROTOCOLS_USED_NO_OMCI;
	}

	ret = OMCI_VOIP_SUCC;
end:
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d! availableSignalProtocols=%d\n",__FUNCTION__,__LINE__,ret,protocol);
	return ret;

}
int setVOIPCfgDataProtoUsed(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;	
	uint8_t protocol = 0;
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info->attributes);
	protocol = voip_cfg_data_ptr->availableSignalProtocols;

	if(omci_voip_set_signal_protocol_used(protocol) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:omci_voip_set_signal_protocol_used fail !\n",__FUNCTION__,__LINE__);
		goto end;
	}

	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d! availableSignalProtocols=%d\n",__FUNCTION__,__LINE__,ret,protocol);
	return ret;

}
int getVOIPCfgDataAvaVoipCfgMethods(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
 	uint32_t methods = 0;
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info->attributes);
	methods = (OMCI_VOIP_CFG_DATA_VOIP_CFG_METHOD_OMCI | OMCI_VOIP_CFG_DATA_VOIP_CFG_METHOD_TR69);
	voip_cfg_data_ptr->availableVoipCfgMethod = methods;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! availableVoipCfgMethod=%d\n",__FUNCTION__,__LINE__,methods);
	return OMCI_VOIP_SUCC;

}
int setVOIPCfgDataMethodsUsed(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = OMCI_VOIP_FAIL;	
	uint8_t cfgMethod = 0;
    uint8_t cfgMethod_o = 0;
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info->attributes);
	
    cfgMethod_o = omci_voip_get_config_method_used();
	cfgMethod = voip_cfg_data_ptr->voipCfgMethodUsed;
    if(cfgMethod_o == cfgMethod)
    {
        ret = OMCI_VOIP_SUCC;
        goto end;
    }
	if(omci_voip_set_config_method_used(cfgMethod) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail!\n",__FUNCTION__,__LINE__);
		goto end;
	}

    if((OMCI_VOIP_CFG_DATA_CFG_METHOD_USED_OMCI == cfgMethod_o) && 
        (OMCI_VOIP_CFG_DATA_CFG_METHOD_USED_OMCI != cfgMethod)){
        /* clear omci create VOIP wan  and recover web wan */
        omci_wan_delete_by_type(E_WAN_SVC_TYPE_VOICE);
        omci_wan_recovery_web(E_WAN_SVC_TYPE_VOICE);
    }

	ret = OMCI_VOIP_SUCC;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return ret=%d! cfgMethod=%d\n",__FUNCTION__,__LINE__,ret,cfgMethod);
	return ret;

}
int getVOIPCfgDatProVersion(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	char pro_version[MAX_BUFFER_SIZE] = {0};
	omci_voip_cfg_data_ptr voip_cfg_data_ptr=NULL;
	
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_cfg_data_ptr = (omci_voip_cfg_data_ptr)(me_info->attributes);

	omci_voip_get_profile_version(pro_version, sizeof(pro_version));

	memcpy(	voip_cfg_data_ptr->profileVersion,pro_version,omci_attr->attriLen);

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: return success! profileVersion=%s\n",__FUNCTION__,__LINE__,pro_version);
	return OMCI_VOIP_SUCC;

}


int setvoipAppSvcProCIDFeatures(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	omci_voip_app_srv_prof_ptr voip_app_srv = NULL;
    char tempBuffer[MAX_BUFFER_SIZE] = {0};
    char nodeName[MAX_BUFFER_SIZE] = {0};
    int i = 0;
	if(me_info == NULL ||	me_info->attributes ==NULL || omci_attr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
		return OMCI_VOIP_FAIL;
	}

	voip_app_srv = (omci_voip_app_srv_prof_ptr)me_info->attributes;

	if(voip_app_srv->cidFeatures & 0x01){
		strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_CID_ENABLE);
	}else{
		strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_CID_DISABLE);
	}
	for(i = 0; i < 2; i++ ){
		sprintf(nodeName, "%s%d", OMCI_VOIP_CALL_CTRL_ENTRY, i);
		omci_tcapi_set(nodeName, OMCI_VOIP_CALLERID_ENABLE, tempBuffer);
		if(omci_tcapi_commit(nodeName)){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail !\n",__FUNCTION__,__LINE__);
			return OMCI_VOIP_FAIL;
		}
	}

	return OMCI_VOIP_SUCC;

}

int setvoipAppSvcProDirectConnectFeature(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{	
    omci_voip_app_srv_prof_ptr voip_app_srv = NULL;
    char tempBuffer[MAX_BUFFER_SIZE] = {0};
    char nodeName[MAX_BUFFER_SIZE] = {0};
    int i = 0;
    if(me_info == NULL ||   me_info->attributes ==NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
        return OMCI_VOIP_FAIL;
    }

    voip_app_srv = (omci_voip_app_srv_prof_ptr)me_info->attributes;
	
 
	if(voip_app_srv->directConnFeature & 0x01){
		strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_VENABLE);
	}else{
		strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_VDISABLE);	
	}
	for(i = 0; i < 2; i++ ){
		sprintf(nodeName, "%s%d", OMCI_VOIP_CALL_CTRL_ENTRY , i);
		omci_tcapi_set(nodeName, OMCI_VOIP_HOT_LINE_ENABLE, tempBuffer);
		if(omci_tcapi_commit(nodeName)){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail !\n",__FUNCTION__,__LINE__);
			return OMCI_VOIP_FAIL;
		}
	}
	return 	OMCI_VOIP_SUCC;
}

int setvoipAppSvcProDirectConnectURIPointer(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
 	omci_voip_app_srv_prof_ptr voip_app_srv = NULL;
 	omci_network_address_ptr network_addr = NULL;
 	omci_large_string_ptr large_str = NULL;
    char nodeName[MAX_BUFFER_SIZE] = {0};
    int i = 0;
    omci_me_info_t me_info_tmp = {0};
    if(me_info == NULL ||   me_info->attributes ==NULL || omci_attr == NULL){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s] parameter is NULL, fail\n",__FUNCTION__);
        return OMCI_VOIP_FAIL;
    }

    voip_app_srv = (omci_voip_app_srv_prof_ptr)me_info->attributes;
		
	/*network address*/
	me_info_tmp.class_id = OMCI_CLASS_ID_NETWORK_ADDRESS;
    me_info_tmp.inst_id = voip_app_srv->directConnUriPtr;	
	if ((voip_app_srv->directConnUriPtr  == 0) || (voip_app_srv->directConnUriPtr == 0xFFFF))
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] network address instance is 0 or 0xFFFF\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_SUCC;
	}
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	if(me_info_tmp.attributes == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	network_addr = (omci_network_address_ptr)me_info_tmp.attributes;

	me_info_tmp.class_id = OMCI_CLASS_ID_LARGE_STRING;
	me_info_tmp.inst_id = network_addr->addressPointer;
	/*large string*/
	if (network_addr->addressPointer  == 0 || network_addr->addressPointer == 0xFFFF)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] large string instance is 0 or 0xFFFF\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}

	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	if(me_info_tmp.attributes == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	large_str = (omci_large_string_ptr)me_info_tmp.attributes;
	
	for(i = 0; i < 2; i++ ){
		sprintf(nodeName, "%s%d", OMCI_VOIP_CALL_CTRL_ENTRY , i);
		omci_tcapi_set(nodeName, OMCI_VOIP_HOT_LINE_NUMBER, large_str->all_part.part);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "FILE = %s, LINE = %d\n",__FILE__, __LINE__);
		if(omci_tcapi_commit(nodeName)){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]:tcapi_commit fail !\n",__FUNCTION__,__LINE__);
			return OMCI_VOIP_FAIL;
		}
	}
	return OMCI_VOIP_SUCC;
}
static int Set_VoIPAppSvcCfgData_CfgManagerNode(uint8_t callWaiting, uint16_t callPro, uint16_t entry_id)
{
    char tempBuffer[MAX_BUFFER_SIZE] = {0};
    char nodeName[MAX_BUFFER_SIZE] = {0};

    sprintf(nodeName, "%s%d", OMCI_VOIP_CALL_CTRL_ENTRY , entry_id);

    /* set call waiting */
    memset(tempBuffer, 0, MAX_BUFFER_SIZE); 
    if(callWaiting & 0x01){
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_VENABLE);
    }else{
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_VDISABLE);		
    }
    omci_tcapi_set(nodeName, OMCI_VOIP_CALL_WAITING_ENABLE, tempBuffer);

    /* set 3way */
    memset(tempBuffer, 0, MAX_BUFFER_SIZE); 
    if(callPro & 0x0001){
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_ENABLE);
    }else{
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_DISABLE);		
    }
    omci_tcapi_set(nodeName, OMCI_VOIP_THREE_WAY_CONF, tempBuffer);

    /* set call transfer */
    memset(tempBuffer, 0, MAX_BUFFER_SIZE); 
    if(callPro & 0x0002){
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_ENABLE);
    }else{
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_DISABLE);		
    }
    omci_tcapi_set(nodeName, OMCI_VOIP_CALL_TRANSFER, tempBuffer);

    /* set Do not distrub */
    memset(tempBuffer, 0, MAX_BUFFER_SIZE); 
    if(callPro & 0x0010){
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_VENABLE);
    }else{
        strcpy(tempBuffer,OMCI_VOIP_APP_SVC_PRO_VDISABLE);		
    }
    omci_tcapi_set(nodeName, OMCI_VOIP_DND_ENABLE, tempBuffer);

    /* commit Node */
	if(omci_adpt_delay_omci_commit_node(nodeName)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s]:tcapi_commit fail ![%d]\n",__FUNCTION__,__LINE__);
        return OMCI_VOIP_FAIL;
    }

    return OMCI_VOIP_SUCC;

}

static int setVoIPSvcProfileForSipUserData(uint16_t instId, uint16_t entryId)
{
	omci_voip_app_srv_prof_ptr voip_app_srv = NULL;
	omci_sip_user_data_ptr sip_user_data = NULL;
	omci_me_info_t me_info_tmp = {0};
	int findFlag=0;

	/*get 9.9.2 Aplication service profile pointer arribute.*/
	me_info_tmp.class_id = OMCI_CLASS_ID_SIP_USER_DATA;
	me_info_tmp.inst_id = instId;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	if(me_info_tmp.attributes == NULL)
	{
	    omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Attribute is NULL.\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_FAIL;
	}
	
	sip_user_data = (omci_sip_user_data_ptr)me_info_tmp.attributes;   
	if(sip_user_data->appSrvProfPtr == 0xffff ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: appSrvProfPtr is 0xFFFF.\n",__FILE__, __LINE__);
		return OMCI_VOIP_SUCC;
	}

	me_info_tmp.class_id = OMCI_CLASS_ID_VOIP_APP_SVC_PROFILE;
	me_info_tmp.inst_id = sip_user_data->appSrvProfPtr;
	if(omci_attr_get_all_data_except_table_attr(&me_info_tmp) != 0 || me_info_tmp.attributes == NULL)
		findFlag = 0;
	else
		findFlag = 1;

	if(findFlag == 1 )
	{
		voip_app_srv = (omci_voip_app_srv_prof_ptr)me_info_tmp.attributes;
		Set_VoIPAppSvcCfgData_CfgManagerNode(voip_app_srv->callWaitingFeatures, voip_app_srv->callProgOrTransFeatures, entryId);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] app_srv_prof(%d) valid, success\n",__FUNCTION__,__LINE__,sip_user_data->appSrvProfPtr);
		return OMCI_VOIP_SUCC;
	}
	else if(findFlag ==0 && sip_user_data->appSrvProfPtr==0) //some olt think  0 is unuseful instance, skip it
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d] inst 0 not exist, skip\n",__FUNCTION__,__LINE__);
		return OMCI_VOIP_SUCC;
	}
	else
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d] app_srv_prof(%d) invalid, fail!\n",__FUNCTION__,__LINE__,sip_user_data->appSrvProfPtr);
		return OMCI_VOIP_FAIL;
	}

}

